Committed by
Gerrit Code Review
Adding VLAN to PeerConnectivityManager
Change-Id: I695087c108dc4d9d2da61992019d8fa3d08c61c1
Showing
6 changed files
with
366 additions
and
84 deletions
... | @@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ... | @@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
22 | import com.fasterxml.jackson.databind.node.ObjectNode; | 22 | import com.fasterxml.jackson.databind.node.ObjectNode; |
23 | import com.google.common.collect.Sets; | 23 | import com.google.common.collect.Sets; |
24 | import org.onlab.packet.IpAddress; | 24 | import org.onlab.packet.IpAddress; |
25 | +import org.onlab.packet.VlanId; | ||
25 | import org.onosproject.core.ApplicationId; | 26 | import org.onosproject.core.ApplicationId; |
26 | import org.onosproject.net.ConnectPoint; | 27 | import org.onosproject.net.ConnectPoint; |
27 | import org.onosproject.net.config.Config; | 28 | import org.onosproject.net.config.Config; |
... | @@ -41,6 +42,7 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -41,6 +42,7 @@ public class BgpConfig extends Config<ApplicationId> { |
41 | public static final String CONNECT_POINT = "connectPoint"; | 42 | public static final String CONNECT_POINT = "connectPoint"; |
42 | public static final String NAME = "name"; | 43 | public static final String NAME = "name"; |
43 | public static final String PEERS = "peers"; | 44 | public static final String PEERS = "peers"; |
45 | + public static final String VLAN = "vlan"; | ||
44 | 46 | ||
45 | /** | 47 | /** |
46 | * Gets the set of configured BGP speakers. | 48 | * Gets the set of configured BGP speakers. |
... | @@ -69,7 +71,10 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -69,7 +71,10 @@ public class BgpConfig extends Config<ApplicationId> { |
69 | name = Optional.of(jsonNode.get(NAME).asText()); | 71 | name = Optional.of(jsonNode.get(NAME).asText()); |
70 | } | 72 | } |
71 | 73 | ||
74 | + VlanId vlan = getVlan(jsonNode); | ||
75 | + | ||
72 | speakers.add(new BgpSpeakerConfig(name, | 76 | speakers.add(new BgpSpeakerConfig(name, |
77 | + vlan, | ||
73 | ConnectPoint.deviceConnectPoint(jsonNode.path(CONNECT_POINT).asText()), | 78 | ConnectPoint.deviceConnectPoint(jsonNode.path(CONNECT_POINT).asText()), |
74 | listenAddresses)); | 79 | listenAddresses)); |
75 | }); | 80 | }); |
... | @@ -77,6 +82,15 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -77,6 +82,15 @@ public class BgpConfig extends Config<ApplicationId> { |
77 | return speakers; | 82 | return speakers; |
78 | } | 83 | } |
79 | 84 | ||
85 | + // If configured, it retreives a VLAN Id from a BGP speaker node | ||
86 | + private VlanId getVlan(JsonNode node) { | ||
87 | + VlanId vlan = VlanId.NONE; | ||
88 | + if (!node.path(VLAN).isMissingNode()) { | ||
89 | + vlan = VlanId.vlanId(node.path(VLAN).asText()); | ||
90 | + } | ||
91 | + return vlan; | ||
92 | + } | ||
93 | + | ||
80 | /** | 94 | /** |
81 | * Examines whether a name of BGP speaker exists in configuration. | 95 | * Examines whether a name of BGP speaker exists in configuration. |
82 | * | 96 | * |
... | @@ -102,6 +116,8 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -102,6 +116,8 @@ public class BgpConfig extends Config<ApplicationId> { |
102 | 116 | ||
103 | speakerNode.put(NAME, speaker.name().get()); | 117 | speakerNode.put(NAME, speaker.name().get()); |
104 | 118 | ||
119 | + speakerNode.put(VLAN, speaker.vlan().toString()); | ||
120 | + | ||
105 | speakerNode.put(CONNECT_POINT, speaker.connectPoint().elementId().toString() | 121 | speakerNode.put(CONNECT_POINT, speaker.connectPoint().elementId().toString() |
106 | + "/" + speaker.connectPoint().port().toString()); | 122 | + "/" + speaker.connectPoint().port().toString()); |
107 | 123 | ||
... | @@ -157,8 +173,8 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -157,8 +173,8 @@ public class BgpConfig extends Config<ApplicationId> { |
157 | /** | 173 | /** |
158 | * Finds BGP speaker peering with a given external peer. | 174 | * Finds BGP speaker peering with a given external peer. |
159 | * | 175 | * |
160 | - * @param peerAddress peering address to be removed | 176 | + * @param peerAddress BGP peer address |
161 | - * @return speaker | 177 | + * @return BGP speaker |
162 | */ | 178 | */ |
163 | public BgpSpeakerConfig getSpeakerFromPeer(IpAddress peerAddress) { | 179 | public BgpSpeakerConfig getSpeakerFromPeer(IpAddress peerAddress) { |
164 | for (BgpConfig.BgpSpeakerConfig speaker : bgpSpeakers()) { | 180 | for (BgpConfig.BgpSpeakerConfig speaker : bgpSpeakers()) { |
... | @@ -207,12 +223,14 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -207,12 +223,14 @@ public class BgpConfig extends Config<ApplicationId> { |
207 | public static class BgpSpeakerConfig { | 223 | public static class BgpSpeakerConfig { |
208 | 224 | ||
209 | private Optional<String> name; | 225 | private Optional<String> name; |
226 | + private VlanId vlanId; | ||
210 | private ConnectPoint connectPoint; | 227 | private ConnectPoint connectPoint; |
211 | private Set<IpAddress> peers; | 228 | private Set<IpAddress> peers; |
212 | 229 | ||
213 | - public BgpSpeakerConfig(Optional<String> name, ConnectPoint connectPoint, | 230 | + public BgpSpeakerConfig(Optional<String> name, VlanId vlanId, |
214 | - Set<IpAddress> peers) { | 231 | + ConnectPoint connectPoint, Set<IpAddress> peers) { |
215 | this.name = checkNotNull(name); | 232 | this.name = checkNotNull(name); |
233 | + this.vlanId = checkNotNull(vlanId); | ||
216 | this.connectPoint = checkNotNull(connectPoint); | 234 | this.connectPoint = checkNotNull(connectPoint); |
217 | this.peers = checkNotNull(peers); | 235 | this.peers = checkNotNull(peers); |
218 | } | 236 | } |
... | @@ -221,6 +239,10 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -221,6 +239,10 @@ public class BgpConfig extends Config<ApplicationId> { |
221 | return name; | 239 | return name; |
222 | } | 240 | } |
223 | 241 | ||
242 | + public VlanId vlan() { | ||
243 | + return vlanId; | ||
244 | + } | ||
245 | + | ||
224 | public ConnectPoint connectPoint() { | 246 | public ConnectPoint connectPoint() { |
225 | return connectPoint; | 247 | return connectPoint; |
226 | } | 248 | } |
... | @@ -252,6 +274,7 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -252,6 +274,7 @@ public class BgpConfig extends Config<ApplicationId> { |
252 | if (obj instanceof BgpSpeakerConfig) { | 274 | if (obj instanceof BgpSpeakerConfig) { |
253 | final BgpSpeakerConfig that = (BgpSpeakerConfig) obj; | 275 | final BgpSpeakerConfig that = (BgpSpeakerConfig) obj; |
254 | return Objects.equals(this.name, that.name) && | 276 | return Objects.equals(this.name, that.name) && |
277 | + Objects.equals(this.vlanId, that.vlanId) && | ||
255 | Objects.equals(this.connectPoint, that.connectPoint) && | 278 | Objects.equals(this.connectPoint, that.connectPoint) && |
256 | Objects.equals(this.peers, that.peers); | 279 | Objects.equals(this.peers, that.peers); |
257 | } | 280 | } |
... | @@ -260,7 +283,7 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -260,7 +283,7 @@ public class BgpConfig extends Config<ApplicationId> { |
260 | 283 | ||
261 | @Override | 284 | @Override |
262 | public int hashCode() { | 285 | public int hashCode() { |
263 | - return Objects.hash(name, connectPoint, peers); | 286 | + return Objects.hash(name, vlanId, connectPoint, peers); |
264 | } | 287 | } |
265 | } | 288 | } |
266 | } | 289 | } | ... | ... |
... | @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ... | @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
21 | import org.junit.Before; | 21 | import org.junit.Before; |
22 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | import org.onlab.packet.IpAddress; | 23 | import org.onlab.packet.IpAddress; |
24 | +import org.onlab.packet.VlanId; | ||
24 | import org.onosproject.TestApplicationId; | 25 | import org.onosproject.TestApplicationId; |
25 | import org.onosproject.core.ApplicationId; | 26 | import org.onosproject.core.ApplicationId; |
26 | import org.onosproject.net.ConnectPoint; | 27 | import org.onosproject.net.ConnectPoint; |
... | @@ -51,6 +52,8 @@ public class BgpConfigTest { | ... | @@ -51,6 +52,8 @@ public class BgpConfigTest { |
51 | private static final IpAddress IP5 = IpAddress.valueOf("10.0.201.1"); | 52 | private static final IpAddress IP5 = IpAddress.valueOf("10.0.201.1"); |
52 | public static final IpAddress IP_NON_EXIST = IpAddress.valueOf("10.101.1.1"); | 53 | public static final IpAddress IP_NON_EXIST = IpAddress.valueOf("10.101.1.1"); |
53 | 54 | ||
55 | + public static final VlanId NO_VLAN = VlanId.NONE; | ||
56 | + | ||
54 | public static final ConnectPoint CONNECT_POINT1 = ConnectPoint. | 57 | public static final ConnectPoint CONNECT_POINT1 = ConnectPoint. |
55 | deviceConnectPoint("of:0000000000000001/1"); | 58 | deviceConnectPoint("of:0000000000000001/1"); |
56 | public static final ConnectPoint CONNECT_POINT2 = ConnectPoint. | 59 | public static final ConnectPoint CONNECT_POINT2 = ConnectPoint. |
... | @@ -230,7 +233,8 @@ public class BgpConfigTest { | ... | @@ -230,7 +233,8 @@ public class BgpConfigTest { |
230 | ConnectPoint connectPoint = CONNECT_POINT1; | 233 | ConnectPoint connectPoint = CONNECT_POINT1; |
231 | Set<IpAddress> connectedPeers = new HashSet<>(Arrays.asList(IP1, IP2, IP3)); | 234 | Set<IpAddress> connectedPeers = new HashSet<>(Arrays.asList(IP1, IP2, IP3)); |
232 | 235 | ||
233 | - return new BgpConfig.BgpSpeakerConfig(speakerName, connectPoint, connectedPeers); | 236 | + return new BgpConfig.BgpSpeakerConfig(speakerName, NO_VLAN, |
237 | + connectPoint, connectedPeers); | ||
234 | } | 238 | } |
235 | 239 | ||
236 | private BgpConfig.BgpSpeakerConfig createNewSpeaker() { | 240 | private BgpConfig.BgpSpeakerConfig createNewSpeaker() { |
... | @@ -239,6 +243,7 @@ public class BgpConfigTest { | ... | @@ -239,6 +243,7 @@ public class BgpConfigTest { |
239 | Set<IpAddress> connectedPeers = new HashSet<>( | 243 | Set<IpAddress> connectedPeers = new HashSet<>( |
240 | Arrays.asList(IP4, IP5)); | 244 | Arrays.asList(IP4, IP5)); |
241 | 245 | ||
242 | - return new BgpConfig.BgpSpeakerConfig(speakerName, connectPoint, connectedPeers); | 246 | + return new BgpConfig.BgpSpeakerConfig(speakerName, NO_VLAN, |
247 | + connectPoint, connectedPeers); | ||
243 | } | 248 | } |
244 | } | 249 | } | ... | ... |
... | @@ -19,6 +19,7 @@ package org.onosproject.routing.cli; | ... | @@ -19,6 +19,7 @@ package org.onosproject.routing.cli; |
19 | import org.apache.karaf.shell.commands.Argument; | 19 | import org.apache.karaf.shell.commands.Argument; |
20 | import org.apache.karaf.shell.commands.Command; | 20 | import org.apache.karaf.shell.commands.Command; |
21 | import org.onlab.packet.IpAddress; | 21 | import org.onlab.packet.IpAddress; |
22 | +import org.onlab.packet.VlanId; | ||
22 | import org.onosproject.cli.AbstractShellCommand; | 23 | import org.onosproject.cli.AbstractShellCommand; |
23 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
24 | import org.onosproject.core.CoreService; | 25 | import org.onosproject.core.CoreService; |
... | @@ -40,12 +41,18 @@ public class AddSpeakerCommand extends AbstractShellCommand { | ... | @@ -40,12 +41,18 @@ public class AddSpeakerCommand extends AbstractShellCommand { |
40 | @Argument(index = 0, name = "name", | 41 | @Argument(index = 0, name = "name", |
41 | description = "Name of the internal BGP speaker", | 42 | description = "Name of the internal BGP speaker", |
42 | required = true, multiValued = false) | 43 | required = true, multiValued = false) |
43 | - String name = null; | 44 | + private String name = null; |
44 | 45 | ||
45 | @Argument(index = 1, name = "connectionPoint", | 46 | @Argument(index = 1, name = "connectionPoint", |
46 | description = "Interface to the BGP speaker", | 47 | description = "Interface to the BGP speaker", |
47 | required = true, multiValued = false) | 48 | required = true, multiValued = false) |
48 | - String connectionPoint = null; | 49 | + private String connectionPoint = null; |
50 | + | ||
51 | + @Argument(index = 2, name = "vlanId", | ||
52 | + description = "VLAN Id of the internal BGP speaker", | ||
53 | + required = false, multiValued = false) | ||
54 | + private String vlanId = null; | ||
55 | + private VlanId vlanIdObj = null; | ||
49 | 56 | ||
50 | private static final String SPEAKER_ADD_SUCCESS = "Speaker Successfully Added."; | 57 | private static final String SPEAKER_ADD_SUCCESS = "Speaker Successfully Added."; |
51 | 58 | ||
... | @@ -57,10 +64,18 @@ public class AddSpeakerCommand extends AbstractShellCommand { | ... | @@ -57,10 +64,18 @@ public class AddSpeakerCommand extends AbstractShellCommand { |
57 | 64 | ||
58 | BgpConfig config = configService.addConfig(appId, BgpConfig.class); | 65 | BgpConfig config = configService.addConfig(appId, BgpConfig.class); |
59 | 66 | ||
60 | - BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name); | 67 | + if (name != null) { |
61 | - if (speaker != null) { | 68 | + BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name); |
62 | - log.debug("Speaker already exists: {}", name); | 69 | + if (speaker != null) { |
63 | - return; | 70 | + log.debug("Speaker already exists: {}", name); |
71 | + return; | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + if (vlanId == null || vlanId.isEmpty()) { | ||
76 | + vlanIdObj = VlanId.NONE; | ||
77 | + } else { | ||
78 | + vlanIdObj = VlanId.vlanId(Short.valueOf(vlanId)); | ||
64 | } | 79 | } |
65 | 80 | ||
66 | addSpeakerToConf(config); | 81 | addSpeakerToConf(config); |
... | @@ -85,6 +100,7 @@ public class AddSpeakerCommand extends AbstractShellCommand { | ... | @@ -85,6 +100,7 @@ public class AddSpeakerCommand extends AbstractShellCommand { |
85 | ConnectPoint connectPoint = ConnectPoint. | 100 | ConnectPoint connectPoint = ConnectPoint. |
86 | deviceConnectPoint(connectionPoint); | 101 | deviceConnectPoint(connectionPoint); |
87 | return new BgpConfig.BgpSpeakerConfig(Optional.ofNullable(name), | 102 | return new BgpConfig.BgpSpeakerConfig(Optional.ofNullable(name), |
88 | - connectPoint, new HashSet<IpAddress>()); | 103 | + vlanIdObj, |
104 | + connectPoint, new HashSet<IpAddress>()); | ||
89 | } | 105 | } |
90 | } | 106 | } | ... | ... |
... | @@ -37,7 +37,7 @@ import java.util.List; | ... | @@ -37,7 +37,7 @@ import java.util.List; |
37 | description = "Lists all BGP speakers") | 37 | description = "Lists all BGP speakers") |
38 | public class BgpSpeakersListCommand extends AbstractShellCommand { | 38 | public class BgpSpeakersListCommand extends AbstractShellCommand { |
39 | 39 | ||
40 | - private static final String FORMAT = "port=%s/%s, peers=%s"; | 40 | + private static final String FORMAT = "port=%s/%s, vlan=%s, peers=%s"; |
41 | private static final String NAME_FORMAT = "%s: " + FORMAT; | 41 | private static final String NAME_FORMAT = "%s: " + FORMAT; |
42 | 42 | ||
43 | private static final Comparator<BgpConfig.BgpSpeakerConfig> SPEAKERS_COMPARATOR = (s1, s2) -> | 43 | private static final Comparator<BgpConfig.BgpSpeakerConfig> SPEAKERS_COMPARATOR = (s1, s2) -> |
... | @@ -67,10 +67,10 @@ public class BgpSpeakersListCommand extends AbstractShellCommand { | ... | @@ -67,10 +67,10 @@ public class BgpSpeakersListCommand extends AbstractShellCommand { |
67 | s -> { | 67 | s -> { |
68 | if (s.name().isPresent()) { | 68 | if (s.name().isPresent()) { |
69 | print(NAME_FORMAT, s.name().get(), s.connectPoint().deviceId(), | 69 | print(NAME_FORMAT, s.name().get(), s.connectPoint().deviceId(), |
70 | - s.connectPoint().port(), s.peers()); | 70 | + s.connectPoint().port(), s.vlan(), s.peers()); |
71 | } else { | 71 | } else { |
72 | print(FORMAT, s.connectPoint().deviceId(), | 72 | print(FORMAT, s.connectPoint().deviceId(), |
73 | - s.connectPoint().port(), s.peers()); | 73 | + s.connectPoint().port(), s.vlan(), s.peers()); |
74 | } | 74 | } |
75 | }); | 75 | }); |
76 | } | 76 | } | ... | ... |
... | @@ -21,6 +21,7 @@ import org.onlab.packet.IPv6; | ... | @@ -21,6 +21,7 @@ import org.onlab.packet.IPv6; |
21 | import org.onlab.packet.IpAddress; | 21 | import org.onlab.packet.IpAddress; |
22 | import org.onlab.packet.IpPrefix; | 22 | import org.onlab.packet.IpPrefix; |
23 | import org.onlab.packet.TpPort; | 23 | import org.onlab.packet.TpPort; |
24 | +import org.onlab.packet.VlanId; | ||
24 | import org.onosproject.core.ApplicationId; | 25 | import org.onosproject.core.ApplicationId; |
25 | import org.onosproject.incubator.net.intf.Interface; | 26 | import org.onosproject.incubator.net.intf.Interface; |
26 | import org.onosproject.incubator.net.intf.InterfaceEvent; | 27 | import org.onosproject.incubator.net.intf.InterfaceEvent; |
... | @@ -166,6 +167,9 @@ public class PeerConnectivityManager { | ... | @@ -166,6 +167,9 @@ public class PeerConnectivityManager { |
166 | private Collection<PointToPointIntent> buildSpeakerIntents(BgpConfig.BgpSpeakerConfig speaker) { | 167 | private Collection<PointToPointIntent> buildSpeakerIntents(BgpConfig.BgpSpeakerConfig speaker) { |
167 | List<PointToPointIntent> intents = new ArrayList<>(); | 168 | List<PointToPointIntent> intents = new ArrayList<>(); |
168 | 169 | ||
170 | + // Get the BGP Speaker VLAN Id | ||
171 | + VlanId bgpSpeakerVlanId = speaker.vlan(); | ||
172 | + | ||
169 | for (IpAddress peerAddress : speaker.peers()) { | 173 | for (IpAddress peerAddress : speaker.peers()) { |
170 | Interface peeringInterface = interfaceService.getMatchingInterface(peerAddress); | 174 | Interface peeringInterface = interfaceService.getMatchingInterface(peerAddress); |
171 | 175 | ||
... | @@ -175,18 +179,23 @@ public class PeerConnectivityManager { | ... | @@ -175,18 +179,23 @@ public class PeerConnectivityManager { |
175 | continue; | 179 | continue; |
176 | } | 180 | } |
177 | 181 | ||
178 | - IpAddress peeringAddress = null; | 182 | + IpAddress bgpSpeakerAddress = null; |
179 | - for (InterfaceIpAddress address : peeringInterface.ipAddresses()) { | 183 | + for (InterfaceIpAddress address : peeringInterface.ipAddressesList()) { |
180 | if (address.subnetAddress().contains(peerAddress)) { | 184 | if (address.subnetAddress().contains(peerAddress)) { |
181 | - peeringAddress = address.ipAddress(); | 185 | + bgpSpeakerAddress = address.ipAddress(); |
182 | break; | 186 | break; |
183 | } | 187 | } |
184 | } | 188 | } |
185 | 189 | ||
186 | - checkNotNull(peeringAddress); | 190 | + checkNotNull(bgpSpeakerAddress); |
191 | + | ||
192 | + VlanId peerVlanId = peeringInterface.vlan(); | ||
187 | 193 | ||
188 | - intents.addAll(buildIntents(speaker.connectPoint(), peeringAddress, | 194 | + intents.addAll(buildIntents(speaker.connectPoint(), bgpSpeakerVlanId, |
189 | - peeringInterface.connectPoint(), peerAddress)); | 195 | + bgpSpeakerAddress, |
196 | + peeringInterface.connectPoint(), | ||
197 | + peerVlanId, | ||
198 | + peerAddress)); | ||
190 | } | 199 | } |
191 | 200 | ||
192 | return intents; | 201 | return intents; |
... | @@ -197,19 +206,25 @@ public class PeerConnectivityManager { | ... | @@ -197,19 +206,25 @@ public class PeerConnectivityManager { |
197 | * IP addresses. | 206 | * IP addresses. |
198 | * | 207 | * |
199 | * @param portOne the first connect point | 208 | * @param portOne the first connect point |
209 | + * @param vlanOne the ingress VLAN | ||
200 | * @param ipOne the first IP address | 210 | * @param ipOne the first IP address |
201 | * @param portTwo the second connect point | 211 | * @param portTwo the second connect point |
212 | + * @param vlanTwo the egress VLAN | ||
202 | * @param ipTwo the second IP address | 213 | * @param ipTwo the second IP address |
203 | * @return the intents to install | 214 | * @return the intents to install |
204 | */ | 215 | */ |
205 | private Collection<PointToPointIntent> buildIntents(ConnectPoint portOne, | 216 | private Collection<PointToPointIntent> buildIntents(ConnectPoint portOne, |
217 | + VlanId vlanOne, | ||
206 | IpAddress ipOne, | 218 | IpAddress ipOne, |
207 | ConnectPoint portTwo, | 219 | ConnectPoint portTwo, |
220 | + VlanId vlanTwo, | ||
208 | IpAddress ipTwo) { | 221 | IpAddress ipTwo) { |
209 | 222 | ||
210 | List<PointToPointIntent> intents = new ArrayList<>(); | 223 | List<PointToPointIntent> intents = new ArrayList<>(); |
211 | 224 | ||
212 | - TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); | 225 | + TrafficTreatment.Builder treatmentToPeer = DefaultTrafficTreatment.builder(); |
226 | + TrafficTreatment.Builder treatmentToSpeaker = DefaultTrafficTreatment.builder(); | ||
227 | + | ||
213 | TrafficSelector selector; | 228 | TrafficSelector selector; |
214 | Key key; | 229 | Key key; |
215 | 230 | ||
... | @@ -224,8 +239,15 @@ public class PeerConnectivityManager { | ... | @@ -224,8 +239,15 @@ public class PeerConnectivityManager { |
224 | icmpProtocol = IPv6.PROTOCOL_ICMP6; | 239 | icmpProtocol = IPv6.PROTOCOL_ICMP6; |
225 | } | 240 | } |
226 | 241 | ||
242 | + // Add treatment for VLAN for traffic going from BGP speaker to BGP peer | ||
243 | + if (!vlanTwo.equals(VlanId.NONE)) { | ||
244 | + treatmentToPeer.setVlanId(vlanTwo); | ||
245 | + } | ||
246 | + | ||
227 | // Path from BGP speaker to BGP peer matching destination TCP port 179 | 247 | // Path from BGP speaker to BGP peer matching destination TCP port 179 |
248 | + | ||
228 | selector = buildSelector(tcpProtocol, | 249 | selector = buildSelector(tcpProtocol, |
250 | + vlanOne, | ||
229 | ipOne, | 251 | ipOne, |
230 | ipTwo, | 252 | ipTwo, |
231 | null, | 253 | null, |
... | @@ -237,7 +259,7 @@ public class PeerConnectivityManager { | ... | @@ -237,7 +259,7 @@ public class PeerConnectivityManager { |
237 | .appId(appId) | 259 | .appId(appId) |
238 | .key(key) | 260 | .key(key) |
239 | .selector(selector) | 261 | .selector(selector) |
240 | - .treatment(treatment) | 262 | + .treatment(treatmentToPeer.build()) |
241 | .ingressPoint(portOne) | 263 | .ingressPoint(portOne) |
242 | .egressPoint(portTwo) | 264 | .egressPoint(portTwo) |
243 | .priority(PRIORITY_OFFSET) | 265 | .priority(PRIORITY_OFFSET) |
... | @@ -245,6 +267,7 @@ public class PeerConnectivityManager { | ... | @@ -245,6 +267,7 @@ public class PeerConnectivityManager { |
245 | 267 | ||
246 | // Path from BGP speaker to BGP peer matching source TCP port 179 | 268 | // Path from BGP speaker to BGP peer matching source TCP port 179 |
247 | selector = buildSelector(tcpProtocol, | 269 | selector = buildSelector(tcpProtocol, |
270 | + vlanOne, | ||
248 | ipOne, | 271 | ipOne, |
249 | ipTwo, | 272 | ipTwo, |
250 | BGP_PORT, | 273 | BGP_PORT, |
... | @@ -256,14 +279,40 @@ public class PeerConnectivityManager { | ... | @@ -256,14 +279,40 @@ public class PeerConnectivityManager { |
256 | .appId(appId) | 279 | .appId(appId) |
257 | .key(key) | 280 | .key(key) |
258 | .selector(selector) | 281 | .selector(selector) |
259 | - .treatment(treatment) | 282 | + .treatment(treatmentToPeer.build()) |
260 | .ingressPoint(portOne) | 283 | .ingressPoint(portOne) |
261 | .egressPoint(portTwo) | 284 | .egressPoint(portTwo) |
262 | .priority(PRIORITY_OFFSET) | 285 | .priority(PRIORITY_OFFSET) |
263 | .build()); | 286 | .build()); |
264 | 287 | ||
288 | + // ICMP path from BGP speaker to BGP peer | ||
289 | + selector = buildSelector(icmpProtocol, | ||
290 | + vlanOne, | ||
291 | + ipOne, | ||
292 | + ipTwo, | ||
293 | + null, | ||
294 | + null); | ||
295 | + | ||
296 | + key = buildKey(ipOne, ipTwo, SUFFIX_ICMP); | ||
297 | + | ||
298 | + intents.add(PointToPointIntent.builder() | ||
299 | + .appId(appId) | ||
300 | + .key(key) | ||
301 | + .selector(selector) | ||
302 | + .treatment(treatmentToPeer.build()) | ||
303 | + .ingressPoint(portOne) | ||
304 | + .egressPoint(portTwo) | ||
305 | + .priority(PRIORITY_OFFSET) | ||
306 | + .build()); | ||
307 | + | ||
308 | + // Add treatment for VLAN for traffic going from BGP peer to BGP speaker | ||
309 | + if (!vlanOne.equals(VlanId.NONE)) { | ||
310 | + treatmentToSpeaker.setVlanId(vlanOne); | ||
311 | + } | ||
312 | + | ||
265 | // Path from BGP peer to BGP speaker matching destination TCP port 179 | 313 | // Path from BGP peer to BGP speaker matching destination TCP port 179 |
266 | selector = buildSelector(tcpProtocol, | 314 | selector = buildSelector(tcpProtocol, |
315 | + vlanTwo, | ||
267 | ipTwo, | 316 | ipTwo, |
268 | ipOne, | 317 | ipOne, |
269 | null, | 318 | null, |
... | @@ -275,7 +324,7 @@ public class PeerConnectivityManager { | ... | @@ -275,7 +324,7 @@ public class PeerConnectivityManager { |
275 | .appId(appId) | 324 | .appId(appId) |
276 | .key(key) | 325 | .key(key) |
277 | .selector(selector) | 326 | .selector(selector) |
278 | - .treatment(treatment) | 327 | + .treatment(treatmentToSpeaker.build()) |
279 | .ingressPoint(portTwo) | 328 | .ingressPoint(portTwo) |
280 | .egressPoint(portOne) | 329 | .egressPoint(portOne) |
281 | .priority(PRIORITY_OFFSET) | 330 | .priority(PRIORITY_OFFSET) |
... | @@ -283,6 +332,7 @@ public class PeerConnectivityManager { | ... | @@ -283,6 +332,7 @@ public class PeerConnectivityManager { |
283 | 332 | ||
284 | // Path from BGP peer to BGP speaker matching source TCP port 179 | 333 | // Path from BGP peer to BGP speaker matching source TCP port 179 |
285 | selector = buildSelector(tcpProtocol, | 334 | selector = buildSelector(tcpProtocol, |
335 | + vlanTwo, | ||
286 | ipTwo, | 336 | ipTwo, |
287 | ipOne, | 337 | ipOne, |
288 | BGP_PORT, | 338 | BGP_PORT, |
... | @@ -294,33 +344,15 @@ public class PeerConnectivityManager { | ... | @@ -294,33 +344,15 @@ public class PeerConnectivityManager { |
294 | .appId(appId) | 344 | .appId(appId) |
295 | .key(key) | 345 | .key(key) |
296 | .selector(selector) | 346 | .selector(selector) |
297 | - .treatment(treatment) | 347 | + .treatment(treatmentToSpeaker.build()) |
298 | .ingressPoint(portTwo) | 348 | .ingressPoint(portTwo) |
299 | .egressPoint(portOne) | 349 | .egressPoint(portOne) |
300 | .priority(PRIORITY_OFFSET) | 350 | .priority(PRIORITY_OFFSET) |
301 | .build()); | 351 | .build()); |
302 | 352 | ||
303 | - // ICMP path from BGP speaker to BGP peer | ||
304 | - selector = buildSelector(icmpProtocol, | ||
305 | - ipOne, | ||
306 | - ipTwo, | ||
307 | - null, | ||
308 | - null); | ||
309 | - | ||
310 | - key = buildKey(ipOne, ipTwo, SUFFIX_ICMP); | ||
311 | - | ||
312 | - intents.add(PointToPointIntent.builder() | ||
313 | - .appId(appId) | ||
314 | - .key(key) | ||
315 | - .selector(selector) | ||
316 | - .treatment(treatment) | ||
317 | - .ingressPoint(portOne) | ||
318 | - .egressPoint(portTwo) | ||
319 | - .priority(PRIORITY_OFFSET) | ||
320 | - .build()); | ||
321 | - | ||
322 | // ICMP path from BGP peer to BGP speaker | 353 | // ICMP path from BGP peer to BGP speaker |
323 | selector = buildSelector(icmpProtocol, | 354 | selector = buildSelector(icmpProtocol, |
355 | + vlanTwo, | ||
324 | ipTwo, | 356 | ipTwo, |
325 | ipOne, | 357 | ipOne, |
326 | null, | 358 | null, |
... | @@ -332,7 +364,7 @@ public class PeerConnectivityManager { | ... | @@ -332,7 +364,7 @@ public class PeerConnectivityManager { |
332 | .appId(appId) | 364 | .appId(appId) |
333 | .key(key) | 365 | .key(key) |
334 | .selector(selector) | 366 | .selector(selector) |
335 | - .treatment(treatment) | 367 | + .treatment(treatmentToSpeaker.build()) |
336 | .ingressPoint(portTwo) | 368 | .ingressPoint(portTwo) |
337 | .egressPoint(portOne) | 369 | .egressPoint(portOne) |
338 | .priority(PRIORITY_OFFSET) | 370 | .priority(PRIORITY_OFFSET) |
... | @@ -351,11 +383,17 @@ public class PeerConnectivityManager { | ... | @@ -351,11 +383,17 @@ public class PeerConnectivityManager { |
351 | * @param dstTcpPort destination TCP port, or null if shouldn't be set | 383 | * @param dstTcpPort destination TCP port, or null if shouldn't be set |
352 | * @return the new traffic selector | 384 | * @return the new traffic selector |
353 | */ | 385 | */ |
354 | - private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, | 386 | + private TrafficSelector buildSelector(byte ipProto, VlanId ingressVlanId, |
387 | + IpAddress srcIp, | ||
355 | IpAddress dstIp, Short srcTcpPort, | 388 | IpAddress dstIp, Short srcTcpPort, |
356 | Short dstTcpPort) { | 389 | Short dstTcpPort) { |
357 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto); | 390 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto); |
358 | 391 | ||
392 | + // Match on any VLAN Id if a VLAN Id configured on the ingress interface | ||
393 | + if (!ingressVlanId.equals(VlanId.NONE)) { | ||
394 | + builder.matchVlanId(VlanId.ANY); | ||
395 | + } | ||
396 | + | ||
359 | if (dstIp.isIp4()) { | 397 | if (dstIp.isIp4()) { |
360 | builder.matchEthType(Ethernet.TYPE_IPV4) | 398 | builder.matchEthType(Ethernet.TYPE_IPV4) |
361 | .matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) | 399 | .matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) | ... | ... |
... | @@ -90,24 +90,35 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -90,24 +90,35 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
90 | 90 | ||
91 | private final String dpid1 = "00:00:00:00:00:00:00:01"; | 91 | private final String dpid1 = "00:00:00:00:00:00:00:01"; |
92 | private final String dpid2 = "00:00:00:00:00:00:00:02"; | 92 | private final String dpid2 = "00:00:00:00:00:00:00:02"; |
93 | + private final String dpid3 = "00:00:00:00:00:00:00:03"; | ||
93 | 94 | ||
94 | private final DeviceId deviceId1 = | 95 | private final DeviceId deviceId1 = |
95 | DeviceId.deviceId(SdnIp.dpidToUri(dpid1)); | 96 | DeviceId.deviceId(SdnIp.dpidToUri(dpid1)); |
96 | private final DeviceId deviceId2 = | 97 | private final DeviceId deviceId2 = |
97 | DeviceId.deviceId(SdnIp.dpidToUri(dpid2)); | 98 | DeviceId.deviceId(SdnIp.dpidToUri(dpid2)); |
99 | + private final DeviceId deviceId3 = | ||
100 | + DeviceId.deviceId(SdnIp.dpidToUri(dpid3)); | ||
98 | 101 | ||
99 | // Interfaces connected to BGP speakers | 102 | // Interfaces connected to BGP speakers |
100 | private final ConnectPoint s1Eth100 = | 103 | private final ConnectPoint s1Eth100 = |
101 | new ConnectPoint(deviceId1, PortNumber.portNumber(100)); | 104 | new ConnectPoint(deviceId1, PortNumber.portNumber(100)); |
105 | + private final ConnectPoint s2Eth100 = | ||
106 | + new ConnectPoint(deviceId2, PortNumber.portNumber(100)); | ||
107 | + private final ConnectPoint s3Eth100 = | ||
108 | + new ConnectPoint(deviceId3, PortNumber.portNumber(100)); | ||
102 | 109 | ||
103 | // Interfaces connected to BGP peers | 110 | // Interfaces connected to BGP peers |
104 | private final ConnectPoint s1Eth1 = | 111 | private final ConnectPoint s1Eth1 = |
105 | new ConnectPoint(deviceId1, PortNumber.portNumber(1)); | 112 | new ConnectPoint(deviceId1, PortNumber.portNumber(1)); |
106 | private final ConnectPoint s2Eth1 = | 113 | private final ConnectPoint s2Eth1 = |
107 | new ConnectPoint(deviceId2, PortNumber.portNumber(1)); | 114 | new ConnectPoint(deviceId2, PortNumber.portNumber(1)); |
115 | + private final ConnectPoint s3Eth1 = | ||
116 | + new ConnectPoint(deviceId3, PortNumber.portNumber(1)); | ||
108 | 117 | ||
109 | - private final TrafficTreatment noTreatment = | 118 | + private static final VlanId NO_VLAN = VlanId.NONE; |
110 | - DefaultTrafficTreatment.emptyTreatment(); | 119 | + private static final VlanId VLAN10 = VlanId.vlanId(Short.valueOf("10")); |
120 | + private static final VlanId VLAN20 = VlanId.vlanId(Short.valueOf("20")); | ||
121 | + private static final VlanId VLAN30 = VlanId.vlanId(Short.valueOf("30")); | ||
111 | 122 | ||
112 | @Before | 123 | @Before |
113 | public void setUp() throws Exception { | 124 | public void setUp() throws Exception { |
... | @@ -139,16 +150,25 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -139,16 +150,25 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
139 | 150 | ||
140 | BgpConfig.BgpSpeakerConfig speaker1 = new BgpConfig.BgpSpeakerConfig( | 151 | BgpConfig.BgpSpeakerConfig speaker1 = new BgpConfig.BgpSpeakerConfig( |
141 | Optional.empty(), | 152 | Optional.empty(), |
142 | - s1Eth100, Collections.singleton(IpAddress.valueOf("192.168.10.1"))); | 153 | + NO_VLAN, s1Eth100, |
154 | + Collections.singleton(IpAddress.valueOf("192.168.10.1"))); | ||
143 | 155 | ||
144 | BgpConfig.BgpSpeakerConfig speaker2 = new BgpConfig.BgpSpeakerConfig( | 156 | BgpConfig.BgpSpeakerConfig speaker2 = new BgpConfig.BgpSpeakerConfig( |
145 | Optional.empty(), | 157 | Optional.empty(), |
146 | - s1Eth100, Sets.newHashSet(IpAddress.valueOf("192.168.20.1"), | 158 | + NO_VLAN, s1Eth100, |
159 | + Sets.newHashSet(IpAddress.valueOf("192.168.20.1"), | ||
147 | IpAddress.valueOf("192.168.30.1"))); | 160 | IpAddress.valueOf("192.168.30.1"))); |
148 | 161 | ||
162 | + BgpConfig.BgpSpeakerConfig speaker3 = new BgpConfig.BgpSpeakerConfig( | ||
163 | + Optional.empty(), | ||
164 | + VLAN30, s3Eth100, | ||
165 | + Sets.newHashSet(IpAddress.valueOf("192.168.40.1"), | ||
166 | + IpAddress.valueOf("192.168.50.1"))); | ||
167 | + | ||
149 | Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers = Sets.newHashSet(); | 168 | Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers = Sets.newHashSet(); |
150 | bgpSpeakers.add(speaker1); | 169 | bgpSpeakers.add(speaker1); |
151 | bgpSpeakers.add(speaker2); | 170 | bgpSpeakers.add(speaker2); |
171 | + bgpSpeakers.add(speaker3); | ||
152 | 172 | ||
153 | return bgpSpeakers; | 173 | return bgpSpeakers; |
154 | } | 174 | } |
... | @@ -173,6 +193,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -173,6 +193,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
173 | VlanId.NONE); | 193 | VlanId.NONE); |
174 | 194 | ||
175 | configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1); | 195 | configuredInterfaces.put(interfaceSw1Eth1, intfsw1eth1); |
196 | + | ||
176 | String interfaceSw2Eth1 = "s2-eth1"; | 197 | String interfaceSw2Eth1 = "s2-eth1"; |
177 | InterfaceIpAddress ia2 = | 198 | InterfaceIpAddress ia2 = |
178 | new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), | 199 | new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"), |
... | @@ -181,6 +202,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -181,6 +202,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
181 | Collections.singletonList(ia2), | 202 | Collections.singletonList(ia2), |
182 | MacAddress.valueOf("00:00:00:00:00:02"), | 203 | MacAddress.valueOf("00:00:00:00:00:02"), |
183 | VlanId.NONE); | 204 | VlanId.NONE); |
205 | + | ||
184 | configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1); | 206 | configuredInterfaces.put(interfaceSw2Eth1, intfsw2eth1); |
185 | 207 | ||
186 | String interfaceSw2Eth1intf2 = "s2-eth1_2"; | 208 | String interfaceSw2Eth1intf2 = "s2-eth1_2"; |
... | @@ -191,14 +213,38 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -191,14 +213,38 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
191 | Collections.singletonList(ia3), | 213 | Collections.singletonList(ia3), |
192 | MacAddress.valueOf("00:00:00:00:00:03"), | 214 | MacAddress.valueOf("00:00:00:00:00:03"), |
193 | VlanId.NONE); | 215 | VlanId.NONE); |
216 | + | ||
194 | configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2); | 217 | configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2); |
195 | 218 | ||
219 | + String interfaceSw3Eth1 = "s3-eth1"; | ||
220 | + InterfaceIpAddress ia4 = | ||
221 | + new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), | ||
222 | + IpPrefix.valueOf("192.168.40.0/24")); | ||
223 | + Interface intfsw3eth1 = new Interface(s3Eth1, | ||
224 | + Collections.singleton(ia4), | ||
225 | + MacAddress.valueOf("00:00:00:00:00:04"), | ||
226 | + VLAN10); | ||
227 | + | ||
228 | + configuredInterfaces.put(interfaceSw3Eth1, intfsw3eth1); | ||
229 | + | ||
230 | + String interfaceSw3Eth1intf2 = "s3-eth1_2"; | ||
231 | + InterfaceIpAddress ia5 = | ||
232 | + new InterfaceIpAddress(IpAddress.valueOf("192.168.50.101"), | ||
233 | + IpPrefix.valueOf("192.168.50.0/24")); | ||
234 | + Interface intfsw3eth1intf2 = new Interface(s3Eth1, | ||
235 | + Collections.singleton(ia5), | ||
236 | + MacAddress.valueOf("00:00:00:00:00:05"), | ||
237 | + VLAN20); | ||
238 | + | ||
239 | + configuredInterfaces.put(interfaceSw3Eth1intf2, intfsw3eth1intf2); | ||
240 | + | ||
196 | expect(interfaceService.getInterfacesByPort(s1Eth1)) | 241 | expect(interfaceService.getInterfacesByPort(s1Eth1)) |
197 | .andReturn(Collections.singleton(intfsw1eth1)).anyTimes(); | 242 | .andReturn(Collections.singleton(intfsw1eth1)).anyTimes(); |
198 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101"))) | 243 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101"))) |
199 | .andReturn(Collections.singleton(intfsw1eth1)).anyTimes(); | 244 | .andReturn(Collections.singleton(intfsw1eth1)).anyTimes(); |
200 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1"))) | 245 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1"))) |
201 | .andReturn(intfsw1eth1).anyTimes(); | 246 | .andReturn(intfsw1eth1).anyTimes(); |
247 | + | ||
202 | expect(interfaceService.getInterfacesByPort(s2Eth1)) | 248 | expect(interfaceService.getInterfacesByPort(s2Eth1)) |
203 | .andReturn(Collections.singleton(intfsw2eth1)).anyTimes(); | 249 | .andReturn(Collections.singleton(intfsw2eth1)).anyTimes(); |
204 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101"))) | 250 | expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101"))) |
... | @@ -211,6 +257,16 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -211,6 +257,16 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
211 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1"))) | 257 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1"))) |
212 | .andReturn(intfsw2eth1intf2).anyTimes(); | 258 | .andReturn(intfsw2eth1intf2).anyTimes(); |
213 | 259 | ||
260 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.40.101"))) | ||
261 | + .andReturn(Collections.singleton(intfsw3eth1)).anyTimes(); | ||
262 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.40.1"))) | ||
263 | + .andReturn(intfsw3eth1).anyTimes(); | ||
264 | + | ||
265 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.50.101"))) | ||
266 | + .andReturn(Collections.singleton(intfsw3eth1intf2)).anyTimes(); | ||
267 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.50.1"))) | ||
268 | + .andReturn(intfsw3eth1intf2).anyTimes(); | ||
269 | + | ||
214 | // Non-existent interface used during one of the tests | 270 | // Non-existent interface used during one of the tests |
215 | expect(interfaceService.getInterfacesByPort(new ConnectPoint( | 271 | expect(interfaceService.getInterfacesByPort(new ConnectPoint( |
216 | DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")), | 272 | DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")), |
... | @@ -245,6 +301,14 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -245,6 +301,14 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
245 | configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1), | 301 | configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1), |
246 | new BgpPeer(dpid2, 1, peer2Sw2Eth1)); | 302 | new BgpPeer(dpid2, 1, peer2Sw2Eth1)); |
247 | 303 | ||
304 | + String peer3Sw3Eth1 = "192.168.40.1"; | ||
305 | + configuredPeers.put(IpAddress.valueOf(peer3Sw3Eth1), | ||
306 | + new BgpPeer(dpid3, 1, peer3Sw3Eth1)); | ||
307 | + | ||
308 | + String peer4Sw3Eth1 = "192.168.50.1"; | ||
309 | + configuredPeers.put(IpAddress.valueOf(peer4Sw3Eth1), | ||
310 | + new BgpPeer(dpid3, 1, peer4Sw3Eth1)); | ||
311 | + | ||
248 | return configuredPeers; | 312 | return configuredPeers; |
249 | } | 313 | } |
250 | 314 | ||
... | @@ -268,6 +332,8 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -268,6 +332,8 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
268 | * The purpose of this method is too simplify the setUpBgpIntents() method, | 332 | * The purpose of this method is too simplify the setUpBgpIntents() method, |
269 | * and to make the setUpBgpIntents() easy to read. | 333 | * and to make the setUpBgpIntents() easy to read. |
270 | * | 334 | * |
335 | + * @param srcVlanId ingress VlanId | ||
336 | + * @param dstVlanId egress VlanId | ||
271 | * @param srcPrefix source IP prefix to match | 337 | * @param srcPrefix source IP prefix to match |
272 | * @param dstPrefix destination IP prefix to match | 338 | * @param dstPrefix destination IP prefix to match |
273 | * @param srcTcpPort source TCP port to match | 339 | * @param srcTcpPort source TCP port to match |
... | @@ -275,9 +341,11 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -275,9 +341,11 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
275 | * @param srcConnectPoint source connect point for PointToPointIntent | 341 | * @param srcConnectPoint source connect point for PointToPointIntent |
276 | * @param dstConnectPoint destination connect point for PointToPointIntent | 342 | * @param dstConnectPoint destination connect point for PointToPointIntent |
277 | */ | 343 | */ |
278 | - private void bgpPathintentConstructor(String srcPrefix, String dstPrefix, | 344 | + private void bgpPathintentConstructor(VlanId srcVlanId, VlanId dstVlanId, |
279 | - Short srcTcpPort, Short dstTcpPort, | 345 | + String srcPrefix, String dstPrefix, |
280 | - ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) { | 346 | + Short srcTcpPort, Short dstTcpPort, |
347 | + ConnectPoint srcConnectPoint, | ||
348 | + ConnectPoint dstConnectPoint) { | ||
281 | 349 | ||
282 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder() | 350 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder() |
283 | .matchEthType(Ethernet.TYPE_IPV4) | 351 | .matchEthType(Ethernet.TYPE_IPV4) |
... | @@ -285,6 +353,16 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -285,6 +353,16 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
285 | .matchIPSrc(IpPrefix.valueOf(srcPrefix)) | 353 | .matchIPSrc(IpPrefix.valueOf(srcPrefix)) |
286 | .matchIPDst(IpPrefix.valueOf(dstPrefix)); | 354 | .matchIPDst(IpPrefix.valueOf(dstPrefix)); |
287 | 355 | ||
356 | + if (!srcVlanId.equals(VlanId.NONE)) { | ||
357 | + builder.matchVlanId(VlanId.ANY); | ||
358 | + } | ||
359 | + | ||
360 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | ||
361 | + | ||
362 | + if (!dstVlanId.equals(VlanId.NONE)) { | ||
363 | + treatment.setVlanId(dstVlanId); | ||
364 | + } | ||
365 | + | ||
288 | if (srcTcpPort != null) { | 366 | if (srcTcpPort != null) { |
289 | builder.matchTcpSrc(TpPort.tpPort(srcTcpPort)); | 367 | builder.matchTcpSrc(TpPort.tpPort(srcTcpPort)); |
290 | } | 368 | } |
... | @@ -299,7 +377,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -299,7 +377,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
299 | .appId(APPID) | 377 | .appId(APPID) |
300 | .key(key) | 378 | .key(key) |
301 | .selector(builder.build()) | 379 | .selector(builder.build()) |
302 | - .treatment(noTreatment) | 380 | + .treatment(treatment.build()) |
303 | .ingressPoint(srcConnectPoint) | 381 | .ingressPoint(srcConnectPoint) |
304 | .egressPoint(dstConnectPoint) | 382 | .egressPoint(dstConnectPoint) |
305 | .build(); | 383 | .build(); |
... | @@ -316,49 +394,118 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -316,49 +394,118 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
316 | 394 | ||
317 | // Start to build intents between BGP speaker1 and BGP peer1 | 395 | // Start to build intents between BGP speaker1 and BGP peer1 |
318 | bgpPathintentConstructor( | 396 | bgpPathintentConstructor( |
319 | - "192.168.10.101/32", "192.168.10.1/32", null, bgpPort, | 397 | + NO_VLAN, NO_VLAN, |
398 | + "192.168.10.101/32", "192.168.10.1/32", | ||
399 | + null, bgpPort, | ||
320 | s1Eth100, s1Eth1); | 400 | s1Eth100, s1Eth1); |
321 | bgpPathintentConstructor( | 401 | bgpPathintentConstructor( |
322 | - "192.168.10.101/32", "192.168.10.1/32", bgpPort, null, | 402 | + NO_VLAN, NO_VLAN, |
403 | + "192.168.10.101/32", "192.168.10.1/32", | ||
404 | + bgpPort, null, | ||
323 | s1Eth100, s1Eth1); | 405 | s1Eth100, s1Eth1); |
324 | 406 | ||
325 | bgpPathintentConstructor( | 407 | bgpPathintentConstructor( |
326 | - "192.168.10.1/32", "192.168.10.101/32", null, bgpPort, | 408 | + NO_VLAN, NO_VLAN, |
409 | + "192.168.10.1/32", "192.168.10.101/32", | ||
410 | + null, bgpPort, | ||
327 | s1Eth1, s1Eth100); | 411 | s1Eth1, s1Eth100); |
328 | bgpPathintentConstructor( | 412 | bgpPathintentConstructor( |
329 | - "192.168.10.1/32", "192.168.10.101/32", bgpPort, null, | 413 | + NO_VLAN, NO_VLAN, |
414 | + "192.168.10.1/32", "192.168.10.101/32", | ||
415 | + bgpPort, null, | ||
330 | s1Eth1, s1Eth100); | 416 | s1Eth1, s1Eth100); |
331 | 417 | ||
332 | // Start to build intents between BGP speaker1 and BGP peer2 | 418 | // Start to build intents between BGP speaker1 and BGP peer2 |
333 | bgpPathintentConstructor( | 419 | bgpPathintentConstructor( |
334 | - "192.168.20.101/32", "192.168.20.1/32", null, bgpPort, | 420 | + NO_VLAN, NO_VLAN, |
421 | + "192.168.20.101/32", "192.168.20.1/32", | ||
422 | + null, bgpPort, | ||
335 | s1Eth100, s2Eth1); | 423 | s1Eth100, s2Eth1); |
336 | bgpPathintentConstructor( | 424 | bgpPathintentConstructor( |
337 | - "192.168.20.101/32", "192.168.20.1/32", bgpPort, null, | 425 | + NO_VLAN, NO_VLAN, |
426 | + "192.168.20.101/32", "192.168.20.1/32", | ||
427 | + bgpPort, null, | ||
338 | s1Eth100, s2Eth1); | 428 | s1Eth100, s2Eth1); |
339 | 429 | ||
340 | bgpPathintentConstructor( | 430 | bgpPathintentConstructor( |
341 | - "192.168.20.1/32", "192.168.20.101/32", null, bgpPort, | 431 | + NO_VLAN, NO_VLAN, |
432 | + "192.168.20.1/32", "192.168.20.101/32", | ||
433 | + null, bgpPort, | ||
342 | s2Eth1, s1Eth100); | 434 | s2Eth1, s1Eth100); |
343 | bgpPathintentConstructor( | 435 | bgpPathintentConstructor( |
344 | - "192.168.20.1/32", "192.168.20.101/32", bgpPort, null, | 436 | + NO_VLAN, NO_VLAN, |
437 | + "192.168.20.1/32", "192.168.20.101/32", | ||
438 | + bgpPort, null, | ||
345 | s2Eth1, s1Eth100); | 439 | s2Eth1, s1Eth100); |
346 | 440 | ||
347 | - // | 441 | + // Start to build intents between BGP speaker2 and BGP peer1 |
348 | - // Start to build intents between BGP speaker3 and BGP peer1 | ||
349 | bgpPathintentConstructor( | 442 | bgpPathintentConstructor( |
350 | - "192.168.30.101/32", "192.168.30.1/32", null, bgpPort, | 443 | + NO_VLAN, NO_VLAN, |
444 | + "192.168.30.101/32", "192.168.30.1/32", | ||
445 | + null, bgpPort, | ||
351 | s1Eth100, s2Eth1); | 446 | s1Eth100, s2Eth1); |
352 | bgpPathintentConstructor( | 447 | bgpPathintentConstructor( |
353 | - "192.168.30.101/32", "192.168.30.1/32", bgpPort, null, | 448 | + NO_VLAN, NO_VLAN, |
449 | + "192.168.30.101/32", "192.168.30.1/32", | ||
450 | + bgpPort, null, | ||
354 | s1Eth100, s2Eth1); | 451 | s1Eth100, s2Eth1); |
355 | 452 | ||
356 | bgpPathintentConstructor( | 453 | bgpPathintentConstructor( |
357 | - "192.168.30.1/32", "192.168.30.101/32", null, bgpPort, | 454 | + NO_VLAN, NO_VLAN, |
455 | + "192.168.30.1/32", "192.168.30.101/32", | ||
456 | + null, bgpPort, | ||
358 | s2Eth1, s1Eth100); | 457 | s2Eth1, s1Eth100); |
359 | bgpPathintentConstructor( | 458 | bgpPathintentConstructor( |
360 | - "192.168.30.1/32", "192.168.30.101/32", bgpPort, null, | 459 | + NO_VLAN, NO_VLAN, |
460 | + "192.168.30.1/32", "192.168.30.101/32", | ||
461 | + bgpPort, null, | ||
361 | s2Eth1, s1Eth100); | 462 | s2Eth1, s1Eth100); |
463 | + | ||
464 | + // Start to build intents between BGP speaker3 and BGP peer4 | ||
465 | + bgpPathintentConstructor( | ||
466 | + VLAN30, VLAN10, | ||
467 | + "192.168.40.101/32", "192.168.40.1/32", | ||
468 | + null, bgpPort, | ||
469 | + s3Eth100, s3Eth1); | ||
470 | + bgpPathintentConstructor( | ||
471 | + VLAN30, VLAN10, | ||
472 | + "192.168.40.101/32", "192.168.40.1/32", | ||
473 | + bgpPort, null, | ||
474 | + s3Eth100, s3Eth1); | ||
475 | + | ||
476 | + bgpPathintentConstructor( | ||
477 | + VLAN10, VLAN30, | ||
478 | + "192.168.40.1/32", "192.168.40.101/32", | ||
479 | + null, bgpPort, | ||
480 | + s3Eth1, s3Eth100); | ||
481 | + bgpPathintentConstructor( | ||
482 | + VLAN10, VLAN30, | ||
483 | + "192.168.40.1/32", "192.168.40.101/32", | ||
484 | + bgpPort, null, | ||
485 | + s3Eth1, s3Eth100); | ||
486 | + | ||
487 | + // Start to build intents between BGP speaker3 and BGP peer5 | ||
488 | + bgpPathintentConstructor( | ||
489 | + VLAN30, VLAN20, | ||
490 | + "192.168.50.101/32", "192.168.50.1/32", | ||
491 | + null, bgpPort, | ||
492 | + s3Eth100, s3Eth1); | ||
493 | + bgpPathintentConstructor( | ||
494 | + VLAN30, VLAN20, | ||
495 | + "192.168.50.101/32", "192.168.50.1/32", | ||
496 | + bgpPort, null, | ||
497 | + s3Eth100, s3Eth1); | ||
498 | + | ||
499 | + bgpPathintentConstructor( | ||
500 | + VLAN20, VLAN30, | ||
501 | + "192.168.50.1/32", "192.168.50.101/32", | ||
502 | + null, bgpPort, | ||
503 | + s3Eth1, s3Eth100); | ||
504 | + bgpPathintentConstructor( | ||
505 | + VLAN20, VLAN30, | ||
506 | + "192.168.50.1/32", "192.168.50.101/32", | ||
507 | + bgpPort, null, | ||
508 | + s3Eth1, s3Eth100); | ||
362 | } | 509 | } |
363 | 510 | ||
364 | /** | 511 | /** |
... | @@ -367,20 +514,33 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -367,20 +514,33 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
367 | * The purpose of this method is too simplify the setUpBgpIntents() method, | 514 | * The purpose of this method is too simplify the setUpBgpIntents() method, |
368 | * and to make the setUpBgpIntents() easy to read. | 515 | * and to make the setUpBgpIntents() easy to read. |
369 | * | 516 | * |
517 | + * @param srcVlanId ingress VlanId | ||
518 | + * @param dstVlanId egress VlanId | ||
370 | * @param srcPrefix source IP prefix to match | 519 | * @param srcPrefix source IP prefix to match |
371 | * @param dstPrefix destination IP prefix to match | 520 | * @param dstPrefix destination IP prefix to match |
372 | * @param srcConnectPoint source connect point for PointToPointIntent | 521 | * @param srcConnectPoint source connect point for PointToPointIntent |
373 | * @param dstConnectPoint destination connect point for PointToPointIntent | 522 | * @param dstConnectPoint destination connect point for PointToPointIntent |
374 | */ | 523 | */ |
375 | - private void icmpPathintentConstructor(String srcPrefix, String dstPrefix, | 524 | + private void icmpPathintentConstructor(VlanId srcVlanId, VlanId dstVlanId, |
376 | - ConnectPoint srcConnectPoint, ConnectPoint dstConnectPoint) { | 525 | + String srcPrefix, String dstPrefix, |
526 | + ConnectPoint srcConnectPoint, | ||
527 | + ConnectPoint dstConnectPoint) { | ||
377 | 528 | ||
378 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 529 | + TrafficSelector.Builder builder = DefaultTrafficSelector.builder() |
379 | .matchEthType(Ethernet.TYPE_IPV4) | 530 | .matchEthType(Ethernet.TYPE_IPV4) |
380 | .matchIPProtocol(IPv4.PROTOCOL_ICMP) | 531 | .matchIPProtocol(IPv4.PROTOCOL_ICMP) |
381 | .matchIPSrc(IpPrefix.valueOf(srcPrefix)) | 532 | .matchIPSrc(IpPrefix.valueOf(srcPrefix)) |
382 | - .matchIPDst(IpPrefix.valueOf(dstPrefix)) | 533 | + .matchIPDst(IpPrefix.valueOf(dstPrefix)); |
383 | - .build(); | 534 | + |
535 | + if (!srcVlanId.equals(VlanId.NONE)) { | ||
536 | + builder.matchVlanId(VlanId.ANY); | ||
537 | + } | ||
538 | + | ||
539 | + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | ||
540 | + | ||
541 | + if (!dstVlanId.equals(VlanId.NONE)) { | ||
542 | + treatment.setVlanId(dstVlanId); | ||
543 | + } | ||
384 | 544 | ||
385 | Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0] | 545 | Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0] |
386 | + "-" + "icmp", APPID); | 546 | + "-" + "icmp", APPID); |
... | @@ -388,8 +548,8 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -388,8 +548,8 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
388 | PointToPointIntent intent = PointToPointIntent.builder() | 548 | PointToPointIntent intent = PointToPointIntent.builder() |
389 | .appId(APPID) | 549 | .appId(APPID) |
390 | .key(key) | 550 | .key(key) |
391 | - .selector(selector) | 551 | + .selector(builder.build()) |
392 | - .treatment(noTreatment) | 552 | + .treatment(treatment.build()) |
393 | .ingressPoint(srcConnectPoint) | 553 | .ingressPoint(srcConnectPoint) |
394 | .egressPoint(dstConnectPoint) | 554 | .egressPoint(dstConnectPoint) |
395 | .build(); | 555 | .build(); |
... | @@ -403,20 +563,52 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -403,20 +563,52 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
403 | private void setUpIcmpIntents() { | 563 | private void setUpIcmpIntents() { |
404 | // Start to build intents between BGP speaker1 and BGP peer1 | 564 | // Start to build intents between BGP speaker1 and BGP peer1 |
405 | icmpPathintentConstructor( | 565 | icmpPathintentConstructor( |
406 | - "192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1); | 566 | + NO_VLAN, NO_VLAN, |
567 | + "192.168.10.101/32", "192.168.10.1/32", | ||
568 | + s1Eth100, s1Eth1); | ||
407 | icmpPathintentConstructor( | 569 | icmpPathintentConstructor( |
408 | - "192.168.10.1/32", "192.168.10.101/32", s1Eth1, s1Eth100); | 570 | + NO_VLAN, NO_VLAN, |
571 | + "192.168.10.1/32", "192.168.10.101/32", | ||
572 | + s1Eth1, s1Eth100); | ||
409 | 573 | ||
410 | // Start to build intents between BGP speaker1 and BGP peer2 | 574 | // Start to build intents between BGP speaker1 and BGP peer2 |
411 | icmpPathintentConstructor( | 575 | icmpPathintentConstructor( |
412 | - "192.168.20.101/32", "192.168.20.1/32", s1Eth100, s2Eth1); | 576 | + NO_VLAN, NO_VLAN, |
577 | + "192.168.20.101/32", "192.168.20.1/32", | ||
578 | + s1Eth100, s2Eth1); | ||
579 | + icmpPathintentConstructor( | ||
580 | + NO_VLAN, NO_VLAN, | ||
581 | + "192.168.20.1/32", "192.168.20.101/32", | ||
582 | + s2Eth1, s1Eth100); | ||
583 | + | ||
584 | + icmpPathintentConstructor( | ||
585 | + NO_VLAN, NO_VLAN, | ||
586 | + "192.168.30.101/32", "192.168.30.1/32", | ||
587 | + s1Eth100, s2Eth1); | ||
588 | + icmpPathintentConstructor( | ||
589 | + NO_VLAN, NO_VLAN, | ||
590 | + "192.168.30.1/32", "192.168.30.101/32", | ||
591 | + s2Eth1, s1Eth100); | ||
592 | + | ||
593 | + // Start to build intents between BGP speaker3 and BGP peer 4 | ||
413 | icmpPathintentConstructor( | 594 | icmpPathintentConstructor( |
414 | - "192.168.20.1/32", "192.168.20.101/32", s2Eth1, s1Eth100); | 595 | + VLAN10, VLAN30, |
596 | + "192.168.40.1/32", "192.168.40.101/32", | ||
597 | + s3Eth1, s3Eth100); | ||
598 | + icmpPathintentConstructor( | ||
599 | + VLAN30, VLAN10, | ||
600 | + "192.168.40.101/32", "192.168.40.1/32", | ||
601 | + s3Eth100, s3Eth1); | ||
415 | 602 | ||
603 | + // Start to build intents between BGP speaker3 and BGP peer 5 | ||
416 | icmpPathintentConstructor( | 604 | icmpPathintentConstructor( |
417 | - "192.168.30.101/32", "192.168.30.1/32", s1Eth100, s2Eth1); | 605 | + VLAN20, VLAN30, |
606 | + "192.168.50.1/32", "192.168.50.101/32", | ||
607 | + s3Eth1, s3Eth100); | ||
418 | icmpPathintentConstructor( | 608 | icmpPathintentConstructor( |
419 | - "192.168.30.1/32", "192.168.30.101/32", s2Eth1, s1Eth100); | 609 | + VLAN30, VLAN20, |
610 | + "192.168.50.101/32", "192.168.50.1/32", | ||
611 | + s3Eth100, s3Eth1); | ||
420 | } | 612 | } |
421 | 613 | ||
422 | /** | 614 | /** |
... | @@ -492,6 +684,14 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -492,6 +684,14 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
492 | .andReturn(Collections.emptySet()).anyTimes(); | 684 | .andReturn(Collections.emptySet()).anyTimes(); |
493 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1"))) | 685 | expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1"))) |
494 | .andReturn(null).anyTimes(); | 686 | .andReturn(null).anyTimes(); |
687 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.40.101"))) | ||
688 | + .andReturn(Collections.emptySet()).anyTimes(); | ||
689 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.40.1"))) | ||
690 | + .andReturn(null).anyTimes(); | ||
691 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.50.101"))) | ||
692 | + .andReturn(Collections.emptySet()).anyTimes(); | ||
693 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.50.1"))) | ||
694 | + .andReturn(null).anyTimes(); | ||
495 | 695 | ||
496 | replay(interfaceService); | 696 | replay(interfaceService); |
497 | 697 | ... | ... |
-
Please register or login to post a comment