Committed by
Gerrit Code Review
Adding VLAN to PeerConnectivityManager
Change-Id: I695087c108dc4d9d2da61992019d8fa3d08c61c1
Showing
6 changed files
with
131 additions
and
49 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)) | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment