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; ...@@ -17,6 +17,7 @@ package org.onosproject.vtn.manager;
17 17
18 import org.onosproject.net.Device; 18 import org.onosproject.net.Device;
19 import org.onosproject.net.Host; 19 import org.onosproject.net.Host;
20 +import org.onosproject.vtnrsc.event.VtnRscEventFeedback;
20 21
21 /** 22 /**
22 * VTN application that applies configuration and flows to the device. 23 * VTN application that applies configuration and flows to the device.
...@@ -67,4 +68,32 @@ public interface VTNService { ...@@ -67,4 +68,32 @@ public interface VTNService {
67 */ 68 */
68 void onHostVanished(Host host); 69 void onHostVanished(Host host);
69 70
71 + /**
72 + * Applies east west flows when neutron created router interface.
73 + *
74 + * @param l3Feedback VtnrscEventFeedback
75 + */
76 + void onRouterInterfaceDetected(VtnRscEventFeedback l3Feedback);
77 +
78 + /**
79 + * Remove east west flows when neutron removed router interface.
80 + *
81 + * @param l3Feedback VtnrscEventFeedback
82 + */
83 + void onRouterInterfaceVanished(VtnRscEventFeedback l3Feedback);
84 +
85 + /**
86 + * Applies north south flows when neutron bind floating ip.
87 + *
88 + * @param l3Feedback VtnrscEventFeedback
89 + */
90 + void onFloatingIpDetected(VtnRscEventFeedback l3Feedback);
91 +
92 + /**
93 + * Applies north south flows when neutron unbind floating ip.
94 + *
95 + * @param l3Feedback VtnrscEventFeedback
96 + */
97 + void onFloatingIpVanished(VtnRscEventFeedback l3Feedback);
98 +
70 } 99 }
......
...@@ -17,12 +17,20 @@ package org.onosproject.vtn.util; ...@@ -17,12 +17,20 @@ package org.onosproject.vtn.util;
17 17
18 import java.util.ArrayList; 18 import java.util.ArrayList;
19 import java.util.Collection; 19 import java.util.Collection;
20 +import java.util.Iterator;
21 +import java.util.List;
20 22
23 +import org.onlab.packet.IpAddress;
21 import org.onosproject.net.AnnotationKeys; 24 import org.onosproject.net.AnnotationKeys;
22 import org.onosproject.net.Device; 25 import org.onosproject.net.Device;
23 import org.onosproject.net.DeviceId; 26 import org.onosproject.net.DeviceId;
24 import org.onosproject.net.Port; 27 import org.onosproject.net.Port;
25 import org.onosproject.net.PortNumber; 28 import org.onosproject.net.PortNumber;
29 +import org.onosproject.store.service.EventuallyConsistentMap;
30 +import org.onosproject.vtnrsc.FixedIp;
31 +import org.onosproject.vtnrsc.TenantNetworkId;
32 +import org.onosproject.vtnrsc.VirtualPort;
33 +import org.onosproject.vtnrsc.VirtualPortId;
26 import org.slf4j.Logger; 34 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory; 35 import org.slf4j.LoggerFactory;
28 36
...@@ -94,4 +102,78 @@ public final class VtnData { ...@@ -94,4 +102,78 @@ public final class VtnData {
94 return localTunnelPorts; 102 return localTunnelPorts;
95 } 103 }
96 104
105 + /**
106 + * Get VirtualPort.
107 + *
108 + * @param vPortStore EventuallyConsistentMap of VirtualPort
109 + * @param vPortId VirtualPortId of the VirtualPort
110 + * @return VirtualPort
111 + */
112 + public static VirtualPort getPort(EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore,
113 + VirtualPortId vPortId) {
114 + if (vPortStore != null) {
115 + return vPortStore.get(vPortId);
116 + }
117 + return null;
118 + }
119 +
120 + /**
121 + * Get VirtualPort.
122 + *
123 + * @param vPortStore EventuallyConsistentMap of VirtualPort
124 + * @param fixedIP FixedIp of the VirtualPort
125 + * @return VirtualPort
126 + */
127 + public static VirtualPort getPort(EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore,
128 + FixedIp fixedIP) {
129 + if (vPortStore != null) {
130 + List<VirtualPort> vPorts = new ArrayList<>();
131 + vPortStore.values().stream().forEach(p -> {
132 + Iterator<FixedIp> fixedIps = p.fixedIps().iterator();
133 + while (fixedIps.hasNext()) {
134 + if (fixedIps.next().equals(fixedIP)) {
135 + vPorts.add(p);
136 + break;
137 + }
138 + }
139 + });
140 + if (vPorts.size() == 0) {
141 + return null;
142 + }
143 + return vPorts.get(0);
144 + }
145 + return null;
146 + }
147 +
148 + /**
149 + * Get VirtualPort.
150 + *
151 + * @param vPortStore EventuallyConsistentMap of VirtualPort
152 + * @param networkId TenantNetworkId of the VirtualPort
153 + * @param ip IpAddress of the VirtualPort
154 + * @return VirtualPort
155 + */
156 + public static VirtualPort getPort(EventuallyConsistentMap<VirtualPortId, VirtualPort> vPortStore,
157 + TenantNetworkId networkId, IpAddress ip) {
158 + if (vPortStore != null) {
159 + List<VirtualPort> vPorts = new ArrayList<>();
160 + vPortStore.values().stream()
161 + .filter(p -> p.networkId().equals(networkId))
162 + .forEach(p -> {
163 + Iterator<FixedIp> fixedIps = p.fixedIps().iterator();
164 + while (fixedIps.hasNext()) {
165 + if (fixedIps.next().ip().equals(ip)) {
166 + vPorts.add(p);
167 + break;
168 + }
169 + }
170 + });
171 + if (vPorts.size() == 0) {
172 + return null;
173 + }
174 + return vPorts.get(0);
175 + }
176 + return null;
177 + }
178 +
97 } 179 }
......
...@@ -17,6 +17,7 @@ package org.onosproject.vtnrsc.virtualport; ...@@ -17,6 +17,7 @@ package org.onosproject.vtnrsc.virtualport;
17 17
18 import java.util.Collection; 18 import java.util.Collection;
19 19
20 +import org.onlab.packet.IpAddress;
20 import org.onosproject.net.DeviceId; 21 import org.onosproject.net.DeviceId;
21 import org.onosproject.vtnrsc.FixedIp; 22 import org.onosproject.vtnrsc.FixedIp;
22 import org.onosproject.vtnrsc.TenantId; 23 import org.onosproject.vtnrsc.TenantId;
...@@ -53,6 +54,15 @@ public interface VirtualPortService { ...@@ -53,6 +54,15 @@ public interface VirtualPortService {
53 VirtualPort getPort(FixedIp fixedIP); 54 VirtualPort getPort(FixedIp fixedIP);
54 55
55 /** 56 /**
57 + * Returns the virtualPort associated with the networkId and ip.
58 + *
59 + * @param networkId the TenantNetworkId identifier
60 + * @param ip the ip identifier
61 + * @return virtualPort.
62 + */
63 + VirtualPort getPort(TenantNetworkId networkId, IpAddress ip);
64 +
65 + /**
56 * Returns the collection of the currently known virtualPort. 66 * Returns the collection of the currently known virtualPort.
57 * @return collection of VirtualPort. 67 * @return collection of VirtualPort.
58 */ 68 */
......
...@@ -72,6 +72,7 @@ public class VirtualPortManager implements VirtualPortService { ...@@ -72,6 +72,7 @@ public class VirtualPortManager implements VirtualPortService {
72 private static final String NETWORKID_NOT_NULL = "NetworkId cannot be null"; 72 private static final String NETWORKID_NOT_NULL = "NetworkId cannot be null";
73 private static final String DEVICEID_NOT_NULL = "DeviceId cannot be null"; 73 private static final String DEVICEID_NOT_NULL = "DeviceId cannot be null";
74 private static final String FIXEDIP_NOT_NULL = "FixedIp cannot be null"; 74 private static final String FIXEDIP_NOT_NULL = "FixedIp cannot be null";
75 + private static final String IP_NOT_NULL = "Ip cannot be null";
75 76
76 protected Map<VirtualPortId, VirtualPort> vPortStore; 77 protected Map<VirtualPortId, VirtualPort> vPortStore;
77 protected ApplicationId appId; 78 protected ApplicationId appId;
...@@ -148,6 +149,27 @@ public class VirtualPortManager implements VirtualPortService { ...@@ -148,6 +149,27 @@ public class VirtualPortManager implements VirtualPortService {
148 } 149 }
149 150
150 @Override 151 @Override
152 + public VirtualPort getPort(TenantNetworkId networkId, IpAddress ip) {
153 + checkNotNull(networkId, NETWORKID_NOT_NULL);
154 + checkNotNull(ip, IP_NOT_NULL);
155 + List<VirtualPort> vPorts = new ArrayList<>();
156 + vPortStore.values().stream().filter(p -> p.networkId().equals(networkId))
157 + .forEach(p -> {
158 + Iterator<FixedIp> fixedIps = p.fixedIps().iterator();
159 + while (fixedIps.hasNext()) {
160 + if (fixedIps.next().ip().equals(ip)) {
161 + vPorts.add(p);
162 + break;
163 + }
164 + }
165 + });
166 + if (vPorts.size() == 0) {
167 + return null;
168 + }
169 + return vPorts.get(0);
170 + }
171 +
172 + @Override
151 public Collection<VirtualPort> getPorts() { 173 public Collection<VirtualPort> getPorts() {
152 return Collections.unmodifiableCollection(vPortStore.values()); 174 return Collections.unmodifiableCollection(vPortStore.values());
153 } 175 }
......