lishuai
Committed by Gerrit Code Review

[ONOS-3520] Add L3 codes for VTNManager class.

Change-Id: I86b5b6e2b863fa78759272e1c8c212017b6a696f
......@@ -17,6 +17,7 @@ package org.onosproject.vtn.manager;
import org.onosproject.net.Device;
import org.onosproject.net.Host;
import org.onosproject.vtnrsc.event.VtnRscEventFeedback;
/**
* VTN application that applies configuration and flows to the device.
......@@ -67,4 +68,32 @@ public interface VTNService {
*/
void onHostVanished(Host host);
/**
* Applies east west flows when neutron created router interface.
*
* @param l3Feedback VtnrscEventFeedback
*/
void onRouterInterfaceDetected(VtnRscEventFeedback l3Feedback);
/**
* Remove east west flows when neutron removed router interface.
*
* @param l3Feedback VtnrscEventFeedback
*/
void onRouterInterfaceVanished(VtnRscEventFeedback l3Feedback);
/**
* Applies north south flows when neutron bind floating ip.
*
* @param l3Feedback VtnrscEventFeedback
*/
void onFloatingIpDetected(VtnRscEventFeedback l3Feedback);
/**
* Applies north south flows when neutron unbind floating ip.
*
* @param l3Feedback VtnrscEventFeedback
*/
void onFloatingIpVanished(VtnRscEventFeedback l3Feedback);
}
......
......@@ -17,12 +17,20 @@ package org.onosproject.vtn.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.onlab.packet.IpAddress;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.store.service.EventuallyConsistentMap;
import org.onosproject.vtnrsc.FixedIp;
import org.onosproject.vtnrsc.TenantNetworkId;
import org.onosproject.vtnrsc.VirtualPort;
import org.onosproject.vtnrsc.VirtualPortId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -94,4 +102,78 @@ public final class VtnData {
return localTunnelPorts;
}
/**
* Get VirtualPort.
*
* @param vPortStore EventuallyConsistentMap of VirtualPort
* @param vPortId VirtualPortId of the VirtualPort
* @return VirtualPort
*/
public static VirtualPort getPort(EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore,
VirtualPortId vPortId) {
if (vPortStore != null) {
return vPortStore.get(vPortId);
}
return null;
}
/**
* Get VirtualPort.
*
* @param vPortStore EventuallyConsistentMap of VirtualPort
* @param fixedIP FixedIp of the VirtualPort
* @return VirtualPort
*/
public static VirtualPort getPort(EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore,
FixedIp fixedIP) {
if (vPortStore != null) {
List<VirtualPort> vPorts = new ArrayList<>();
vPortStore.values().stream().forEach(p -> {
Iterator<FixedIp> fixedIps = p.fixedIps().iterator();
while (fixedIps.hasNext()) {
if (fixedIps.next().equals(fixedIP)) {
vPorts.add(p);
break;
}
}
});
if (vPorts.size() == 0) {
return null;
}
return vPorts.get(0);
}
return null;
}
/**
* Get VirtualPort.
*
* @param vPortStore EventuallyConsistentMap of VirtualPort
* @param networkId TenantNetworkId of the VirtualPort
* @param ip IpAddress of the VirtualPort
* @return VirtualPort
*/
public static VirtualPort getPort(EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore,
TenantNetworkId networkId, IpAddress ip) {
if (vPortStore != null) {
List<VirtualPort> vPorts = new ArrayList<>();
vPortStore.values().stream()
.filter(p -> p.networkId().equals(networkId))
.forEach(p -> {
Iterator<FixedIp> fixedIps = p.fixedIps().iterator();
while (fixedIps.hasNext()) {
if (fixedIps.next().ip().equals(ip)) {
vPorts.add(p);
break;
}
}
});
if (vPorts.size() == 0) {
return null;
}
return vPorts.get(0);
}
return null;
}
}
......
......@@ -17,6 +17,7 @@ package org.onosproject.vtnrsc.virtualport;
import java.util.Collection;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.vtnrsc.FixedIp;
import org.onosproject.vtnrsc.TenantId;
......@@ -53,6 +54,15 @@ public interface VirtualPortService {
VirtualPort getPort(FixedIp fixedIP);
/**
* Returns the virtualPort associated with the networkId and ip.
*
* @param networkId the TenantNetworkId identifier
* @param ip the ip identifier
* @return virtualPort.
*/
VirtualPort getPort(TenantNetworkId networkId, IpAddress ip);
/**
* Returns the collection of the currently known virtualPort.
* @return collection of VirtualPort.
*/
......
......@@ -72,6 +72,7 @@ public class VirtualPortManager implements VirtualPortService {
private static final String NETWORKID_NOT_NULL = "NetworkId cannot be null";
private static final String DEVICEID_NOT_NULL = "DeviceId cannot be null";
private static final String FIXEDIP_NOT_NULL = "FixedIp cannot be null";
private static final String IP_NOT_NULL = "Ip cannot be null";
protected Map<VirtualPortId, VirtualPort> vPortStore;
protected ApplicationId appId;
......@@ -148,6 +149,27 @@ public class VirtualPortManager implements VirtualPortService {
}
@Override
public VirtualPort getPort(TenantNetworkId networkId, IpAddress ip) {
checkNotNull(networkId, NETWORKID_NOT_NULL);
checkNotNull(ip, IP_NOT_NULL);
List<VirtualPort> vPorts = new ArrayList<>();
vPortStore.values().stream().filter(p -> p.networkId().equals(networkId))
.forEach(p -> {
Iterator<FixedIp> fixedIps = p.fixedIps().iterator();
while (fixedIps.hasNext()) {
if (fixedIps.next().ip().equals(ip)) {
vPorts.add(p);
break;
}
}
});
if (vPorts.size() == 0) {
return null;
}
return vPorts.get(0);
}
@Override
public Collection<VirtualPort> getPorts() {
return Collections.unmodifiableCollection(vPortStore.values());
}
......