Luca Prete
Committed by Brian O'Connor

ONOS-5236 - Adapt SDN-IP to the new intent framework APIs

Change-Id: I89b60602247a25a1879e4394a60c57d480881f74
...@@ -21,6 +21,8 @@ import org.apache.felix.scr.annotations.Component; ...@@ -21,6 +21,8 @@ import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Deactivate; 21 import org.apache.felix.scr.annotations.Deactivate;
22 import org.apache.felix.scr.annotations.Reference; 22 import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality; 23 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 +import org.onlab.packet.Ethernet;
25 +import org.onlab.packet.VlanId;
24 import org.onosproject.core.ApplicationId; 26 import org.onosproject.core.ApplicationId;
25 import org.onosproject.core.CoreService; 27 import org.onosproject.core.CoreService;
26 import org.onosproject.incubator.net.intf.Interface; 28 import org.onosproject.incubator.net.intf.Interface;
...@@ -42,8 +44,6 @@ import org.onosproject.routing.config.BgpConfig; ...@@ -42,8 +44,6 @@ import org.onosproject.routing.config.BgpConfig;
42 import java.util.HashSet; 44 import java.util.HashSet;
43 import java.util.Set; 45 import java.util.Set;
44 46
45 -import static org.onosproject.net.HostId.hostId;
46 -
47 /** 47 /**
48 * Manages neighbour message handlers for the use case of internal BGP speakers 48 * Manages neighbour message handlers for the use case of internal BGP speakers
49 * connected to the network at some point that are exchanging neighbour 49 * connected to the network at some point that are exchanging neighbour
...@@ -154,11 +154,18 @@ public class BgpSpeakerNeighbourHandler { ...@@ -154,11 +154,18 @@ public class BgpSpeakerNeighbourHandler {
154 case REPLY: 154 case REPLY:
155 // Proxy replies over to our internal BGP speaker if the host 155 // Proxy replies over to our internal BGP speaker if the host
156 // is known to us 156 // is known to us
157 - Host h = hostService.getHost(hostId(context.dstMac(), context.vlan())); 157 + Host h = hostService.getHostsByMac(context.dstMac()).stream()
158 - 158 + .findFirst()
159 + .get();
159 if (h == null) { 160 if (h == null) {
160 context.drop(); 161 context.drop();
161 } else { 162 } else {
163 + VlanId bgpSpeakerVlanId = h.vlan();
164 + if (!bgpSpeakerVlanId.equals(VlanId.NONE)) {
165 + context.packet().setVlanID(bgpSpeakerVlanId.toShort());
166 + } else {
167 + context.packet().setVlanID(Ethernet.VLAN_UNTAGGED);
168 + }
162 context.forward(h.location()); 169 context.forward(h.location());
163 } 170 }
164 break; 171 break;
...@@ -179,9 +186,6 @@ public class BgpSpeakerNeighbourHandler { ...@@ -179,9 +186,6 @@ public class BgpSpeakerNeighbourHandler {
179 // For messages coming from a BGP speaker, look at the sender address 186 // For messages coming from a BGP speaker, look at the sender address
180 // to find the interface to proxy to 187 // to find the interface to proxy to
181 interfaceService.getInterfacesByIp(context.sender()) 188 interfaceService.getInterfacesByIp(context.sender())
182 - .stream()
183 - .filter(intf -> intf.vlan().equals(context.vlan()))
184 - .map(intf -> intf.connectPoint())
185 .forEach(context::forward); 189 .forEach(context::forward);
186 } 190 }
187 } 191 }
......
...@@ -239,16 +239,9 @@ public class PeerConnectivityManager { ...@@ -239,16 +239,9 @@ public class PeerConnectivityManager {
239 } 239 }
240 240
241 // Add VLAN treatment for traffic going from BGP speaker to BGP peer 241 // Add VLAN treatment for traffic going from BGP speaker to BGP peer
242 - if (!vlanOne.equals(vlanTwo)) { 242 + treatmentToPeer = applyVlanTreatment(vlanOne, vlanTwo, treatmentToPeer);
243 - if (vlanTwo.equals(VlanId.NONE)) {
244 - treatmentToPeer.popVlan();
245 - } else {
246 - treatmentToPeer.setVlanId(vlanTwo);
247 - }
248 - }
249 243
250 // Path from BGP speaker to BGP peer matching destination TCP port 179 244 // Path from BGP speaker to BGP peer matching destination TCP port 179
251 -
252 selector = buildSelector(tcpProtocol, 245 selector = buildSelector(tcpProtocol,
253 vlanOne, 246 vlanOne,
254 ipOne, 247 ipOne,
...@@ -309,13 +302,7 @@ public class PeerConnectivityManager { ...@@ -309,13 +302,7 @@ public class PeerConnectivityManager {
309 .build()); 302 .build());
310 303
311 // Add VLAN treatment for traffic going from BGP peer to BGP speaker 304 // Add VLAN treatment for traffic going from BGP peer to BGP speaker
312 - if (!vlanTwo.equals(vlanOne)) { 305 + treatmentToSpeaker = applyVlanTreatment(vlanTwo, vlanOne, treatmentToSpeaker);
313 - if (vlanOne.equals(VlanId.NONE)) {
314 - treatmentToSpeaker.popVlan();
315 - } else {
316 - treatmentToSpeaker.setVlanId(vlanOne);
317 - }
318 - }
319 306
320 // Path from BGP peer to BGP speaker matching destination TCP port 179 307 // Path from BGP peer to BGP speaker matching destination TCP port 179
321 selector = buildSelector(tcpProtocol, 308 selector = buildSelector(tcpProtocol,
...@@ -396,9 +383,9 @@ public class PeerConnectivityManager { ...@@ -396,9 +383,9 @@ public class PeerConnectivityManager {
396 Short dstTcpPort) { 383 Short dstTcpPort) {
397 TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto); 384 TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto);
398 385
399 - // Match on any VLAN Id if a VLAN Id configured on the ingress interface 386 + // Match on VLAN Id if a VLAN Id configured on the ingress interface
400 if (!ingressVlanId.equals(VlanId.NONE)) { 387 if (!ingressVlanId.equals(VlanId.NONE)) {
401 - builder.matchVlanId(VlanId.ANY); 388 + builder.matchVlanId(ingressVlanId);
402 } 389 }
403 390
404 if (dstIp.isIp4()) { 391 if (dstIp.isIp4()) {
...@@ -422,6 +409,31 @@ public class PeerConnectivityManager { ...@@ -422,6 +409,31 @@ public class PeerConnectivityManager {
422 return builder.build(); 409 return builder.build();
423 } 410 }
424 411
412 + /*
413 + * Adds the VLAN Id treatment before building the intents, depending on how
414 + * the VLAN Ids of the BGP speakers and the BGP peers are configured.
415 + */
416 + private TrafficTreatment.Builder applyVlanTreatment(VlanId vlanOne,
417 + VlanId vlanTwo,
418 + TrafficTreatment.Builder treatment) {
419 + if (!vlanOne.equals(vlanTwo)) {
420 + // VLANs are different. Do some VLAN treatment
421 + if (vlanTwo.equals(VlanId.NONE)) {
422 + // VLAN two is none. VLAN one is set. Do a pop
423 + treatment.popVlan();
424 + } else {
425 + // Either both VLANs are set or vlanOne is not
426 + if (vlanOne.equals(VlanId.NONE)) {
427 + // VLAN one is none. VLAN two is set. Push the VLAN header
428 + treatment.pushVlan();
429 + }
430 + // Set the VLAN Id to the egress VLAN Id
431 + treatment.setVlanId(vlanTwo);
432 + }
433 + }
434 + return treatment;
435 + }
436 +
425 /** 437 /**
426 * Builds an intent Key for a point-to-point intent based off the source 438 * Builds an intent Key for a point-to-point intent based off the source
427 * and destination IP address, as well as a suffix String to distinguish 439 * and destination IP address, as well as a suffix String to distinguish
......
...@@ -316,7 +316,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { ...@@ -316,7 +316,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
316 .matchIPDst(IpPrefix.valueOf(dstPrefix)); 316 .matchIPDst(IpPrefix.valueOf(dstPrefix));
317 317
318 if (!srcVlanId.equals(VlanId.NONE)) { 318 if (!srcVlanId.equals(VlanId.NONE)) {
319 - builder.matchVlanId(VlanId.ANY); 319 + builder.matchVlanId(srcVlanId);
320 } 320 }
321 321
322 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); 322 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
...@@ -495,7 +495,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { ...@@ -495,7 +495,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
495 .matchIPDst(IpPrefix.valueOf(dstPrefix)); 495 .matchIPDst(IpPrefix.valueOf(dstPrefix));
496 496
497 if (!srcVlanId.equals(VlanId.NONE)) { 497 if (!srcVlanId.equals(VlanId.NONE)) {
498 - builder.matchVlanId(VlanId.ANY); 498 + builder.matchVlanId(srcVlanId);
499 } 499 }
500 500
501 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); 501 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
......
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -package org.onosproject.sdnip;
18 -
19 -import com.google.common.collect.Lists;
20 -import com.google.common.collect.Sets;
21 -import org.junit.Before;
22 -import org.junit.Test;
23 -import org.onlab.packet.Ethernet;
24 -import org.onlab.packet.Ip4Address;
25 -import org.onlab.packet.Ip4Prefix;
26 -import org.onlab.packet.IpPrefix;
27 -import org.onlab.packet.MacAddress;
28 -import org.onlab.packet.VlanId;
29 -import org.onosproject.TestApplicationId;
30 -import org.onosproject.core.ApplicationId;
31 -import org.onosproject.core.CoreServiceAdapter;
32 -import org.onosproject.incubator.net.intf.Interface;
33 -import org.onosproject.incubator.net.intf.InterfaceListener;
34 -import org.onosproject.incubator.net.intf.InterfaceService;
35 -import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
36 -import org.onosproject.incubator.net.routing.ResolvedRoute;
37 -import org.onosproject.incubator.net.routing.RouteEvent;
38 -import org.onosproject.incubator.net.routing.RouteListener;
39 -import org.onosproject.incubator.net.routing.RouteServiceAdapter;
40 -import org.onosproject.net.ConnectPoint;
41 -import org.onosproject.net.DeviceId;
42 -import org.onosproject.net.PortNumber;
43 -import org.onosproject.net.flow.DefaultTrafficSelector;
44 -import org.onosproject.net.flow.DefaultTrafficTreatment;
45 -import org.onosproject.net.flow.TrafficSelector;
46 -import org.onosproject.net.flow.TrafficTreatment;
47 -import org.onosproject.net.host.InterfaceIpAddress;
48 -import org.onosproject.net.intent.AbstractIntentTest;
49 -import org.onosproject.net.intent.Key;
50 -import org.onosproject.net.intent.MultiPointToSinglePointIntent;
51 -import org.onosproject.routing.IntentSynchronizationService;
52 -
53 -import java.util.Collections;
54 -import java.util.HashSet;
55 -import java.util.List;
56 -import java.util.Set;
57 -
58 -import static org.easymock.EasyMock.*;
59 -import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId;
60 -
61 -/**
62 - * Unit tests for SdnIpFib.
63 - */
64 -public class SdnIpFibNoVlanstoVlanTest extends AbstractIntentTest {
65 -
66 - private InterfaceService interfaceService;
67 -
68 - private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
69 - DeviceId.deviceId("of:0000000000000001"),
70 - PortNumber.portNumber(1));
71 -
72 - private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
73 - DeviceId.deviceId("of:0000000000000002"),
74 - PortNumber.portNumber(1));
75 -
76 - private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
77 - DeviceId.deviceId("of:0000000000000003"),
78 - PortNumber.portNumber(1));
79 -
80 - private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
81 -
82 - private SdnIpFib sdnipFib;
83 - private IntentSynchronizationService intentSynchronizer;
84 - private final Set<Interface> interfaces = Sets.newHashSet();
85 -
86 - private static final ApplicationId APPID = TestApplicationId.create("SDNIP");
87 -
88 - private RouteListener routeListener;
89 - private InterfaceListener interfaceListener;
90 -
91 - @Before
92 - public void setUp() throws Exception {
93 - super.setUp();
94 -
95 - interfaceService = createMock(InterfaceService.class);
96 -
97 - interfaceService.addListener(anyObject(InterfaceListener.class));
98 - expectLastCall().andDelegateTo(new InterfaceServiceDelegate());
99 -
100 - // These will set expectations on routingConfig and interfaceService
101 - setUpInterfaceService();
102 -
103 - replay(interfaceService);
104 -
105 - intentSynchronizer = createMock(IntentSynchronizationService.class);
106 -
107 - sdnipFib = new SdnIpFib();
108 - sdnipFib.routeService = new TestRouteService();
109 - sdnipFib.coreService = new TestCoreService();
110 - sdnipFib.interfaceService = interfaceService;
111 - sdnipFib.intentSynchronizer = intentSynchronizer;
112 -
113 - sdnipFib.activate();
114 - }
115 -
116 - /**
117 - * Sets up the interface service.
118 - */
119 - private void setUpInterfaceService() {
120 - List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList();
121 - interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24"));
122 - Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1,
123 - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
124 - VlanId.NONE);
125 - interfaces.add(sw1Eth1);
126 -
127 - List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList();
128 - interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24"));
129 - Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1,
130 - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
131 - VlanId.NONE);
132 - interfaces.add(sw2Eth1);
133 -
134 - InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24");
135 - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1,
136 - Lists.newArrayList(interfaceIpAddress3),
137 - MacAddress.valueOf("00:00:00:00:00:03"),
138 - VlanId.vlanId((short) 1));
139 - interfaces.add(sw3Eth1);
140 -
141 - expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
142 - Collections.singleton(sw1Eth1)).anyTimes();
143 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1")))
144 - .andReturn(sw1Eth1).anyTimes();
145 - expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn(
146 - Collections.singleton(sw2Eth1)).anyTimes();
147 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1")))
148 - .andReturn(sw2Eth1).anyTimes();
149 - expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
150 - Collections.singleton(sw3Eth1)).anyTimes();
151 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1")))
152 - .andReturn(sw3Eth1).anyTimes();
153 - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
154 - }
155 -
156 - /**
157 - * Tests adding a route. Ingresses with no VLAN and next hop with VLAN.
158 - *
159 - * We verify that the synchronizer records the correct state and that the
160 - * correct intent is submitted to the IntentService.
161 - */
162 - @Test
163 - public void testRouteAdd() {
164 - ResolvedRoute route = new ResolvedRoute(PREFIX1,
165 - Ip4Address.valueOf("192.168.30.1"),
166 - MacAddress.valueOf("00:00:00:00:00:03"));
167 -
168 - // Construct a MultiPointToSinglePointIntent intent
169 - TrafficSelector.Builder selectorBuilder =
170 - DefaultTrafficSelector.builder();
171 - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4)
172 - .matchIPDst(PREFIX1);
173 -
174 - TrafficTreatment.Builder treatmentBuilder =
175 - DefaultTrafficTreatment.builder();
176 - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03"))
177 - .setVlanId(VlanId.vlanId((short) 1));
178 -
179 - Set<ConnectPoint> ingressPoints = new HashSet<>();
180 - ingressPoints.add(SW1_ETH1);
181 - ingressPoints.add(SW2_ETH1);
182 -
183 - MultiPointToSinglePointIntent intent =
184 - MultiPointToSinglePointIntent.builder()
185 - .appId(APPID)
186 - .key(Key.of(PREFIX1.toString(), APPID))
187 - .selector(selectorBuilder.build())
188 - .treatment(treatmentBuilder.build())
189 - .ingressPoints(ingressPoints)
190 - .egressPoint(SW3_ETH1)
191 - .constraints(SdnIpFib.CONSTRAINTS)
192 - .build();
193 -
194 - // Setup the expected intents
195 - intentSynchronizer.submit(eqExceptId(intent));
196 -
197 - replay(intentSynchronizer);
198 -
199 - // Send in the added event
200 - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
201 -
202 - verify(intentSynchronizer);
203 - }
204 -
205 - private class TestCoreService extends CoreServiceAdapter {
206 - @Override
207 - public ApplicationId getAppId(String name) {
208 - return APPID;
209 - }
210 - }
211 -
212 - private class TestRouteService extends RouteServiceAdapter {
213 - @Override
214 - public void addListener(RouteListener routeListener) {
215 - SdnIpFibNoVlanstoVlanTest.this.routeListener = routeListener;
216 - }
217 - }
218 -
219 - private class InterfaceServiceDelegate extends InterfaceServiceAdapter {
220 - @Override
221 - public void addListener(InterfaceListener listener) {
222 - SdnIpFibNoVlanstoVlanTest.this.interfaceListener = listener;
223 - }
224 - }
225 -}
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -package org.onosproject.sdnip;
18 -
19 -import com.google.common.collect.Lists;
20 -import com.google.common.collect.Sets;
21 -import org.junit.Before;
22 -import org.junit.Test;
23 -import org.onlab.packet.Ethernet;
24 -import org.onlab.packet.Ip4Address;
25 -import org.onlab.packet.Ip4Prefix;
26 -import org.onlab.packet.IpPrefix;
27 -import org.onlab.packet.MacAddress;
28 -import org.onlab.packet.VlanId;
29 -import org.onosproject.TestApplicationId;
30 -import org.onosproject.core.ApplicationId;
31 -import org.onosproject.core.CoreServiceAdapter;
32 -import org.onosproject.incubator.net.intf.Interface;
33 -import org.onosproject.incubator.net.intf.InterfaceListener;
34 -import org.onosproject.incubator.net.intf.InterfaceService;
35 -import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
36 -import org.onosproject.incubator.net.routing.ResolvedRoute;
37 -import org.onosproject.incubator.net.routing.RouteEvent;
38 -import org.onosproject.incubator.net.routing.RouteListener;
39 -import org.onosproject.incubator.net.routing.RouteServiceAdapter;
40 -import org.onosproject.net.ConnectPoint;
41 -import org.onosproject.net.DeviceId;
42 -import org.onosproject.net.PortNumber;
43 -import org.onosproject.net.flow.DefaultTrafficSelector;
44 -import org.onosproject.net.flow.DefaultTrafficTreatment;
45 -import org.onosproject.net.flow.TrafficSelector;
46 -import org.onosproject.net.flow.TrafficTreatment;
47 -import org.onosproject.net.host.InterfaceIpAddress;
48 -import org.onosproject.net.intent.AbstractIntentTest;
49 -import org.onosproject.net.intent.Key;
50 -import org.onosproject.net.intent.MultiPointToSinglePointIntent;
51 -import org.onosproject.routing.IntentSynchronizationService;
52 -
53 -import java.util.Collections;
54 -import java.util.HashSet;
55 -import java.util.List;
56 -import java.util.Set;
57 -
58 -import static org.easymock.EasyMock.*;
59 -import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId;
60 -
61 -/**
62 - * Unit tests for SdnIpFib.
63 - */
64 -public class SdnIpFibVlansToVlanDifferentTest extends AbstractIntentTest {
65 -
66 - private InterfaceService interfaceService;
67 -
68 - private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
69 - DeviceId.deviceId("of:0000000000000001"),
70 - PortNumber.portNumber(1));
71 -
72 - private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
73 - DeviceId.deviceId("of:0000000000000002"),
74 - PortNumber.portNumber(1));
75 -
76 - private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
77 - DeviceId.deviceId("of:0000000000000003"),
78 - PortNumber.portNumber(1));
79 -
80 - private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
81 -
82 - private SdnIpFib sdnipFib;
83 - private IntentSynchronizationService intentSynchronizer;
84 - private final Set<Interface> interfaces = Sets.newHashSet();
85 -
86 - private static final ApplicationId APPID = TestApplicationId.create("SDNIP");
87 -
88 - private RouteListener routeListener;
89 - private InterfaceListener interfaceListener;
90 -
91 - @Before
92 - public void setUp() throws Exception {
93 - super.setUp();
94 -
95 - interfaceService = createMock(InterfaceService.class);
96 -
97 - interfaceService.addListener(anyObject(InterfaceListener.class));
98 - expectLastCall().andDelegateTo(new InterfaceServiceDelegate());
99 -
100 - // These will set expectations on routingConfig and interfaceService
101 - setUpInterfaceService();
102 -
103 - replay(interfaceService);
104 -
105 - intentSynchronizer = createMock(IntentSynchronizationService.class);
106 -
107 - sdnipFib = new SdnIpFib();
108 - sdnipFib.routeService = new TestRouteService();
109 - sdnipFib.coreService = new TestCoreService();
110 - sdnipFib.interfaceService = interfaceService;
111 - sdnipFib.intentSynchronizer = intentSynchronizer;
112 -
113 - sdnipFib.activate();
114 - }
115 -
116 - /**
117 - * Sets up the interface service.
118 - */
119 - private void setUpInterfaceService() {
120 - List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList();
121 - interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24"));
122 - Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1,
123 - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
124 - VlanId.vlanId((short) 1));
125 - interfaces.add(sw1Eth1);
126 -
127 - List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList();
128 - interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24"));
129 - Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1,
130 - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
131 - VlanId.vlanId((short) 1));
132 - interfaces.add(sw2Eth1);
133 -
134 - InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24");
135 - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1,
136 - Lists.newArrayList(interfaceIpAddress3),
137 - MacAddress.valueOf("00:00:00:00:00:03"),
138 - VlanId.vlanId((short) 2));
139 - interfaces.add(sw3Eth1);
140 -
141 - expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
142 - Collections.singleton(sw1Eth1)).anyTimes();
143 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1")))
144 - .andReturn(sw1Eth1).anyTimes();
145 - expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn(
146 - Collections.singleton(sw2Eth1)).anyTimes();
147 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1")))
148 - .andReturn(sw2Eth1).anyTimes();
149 - expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
150 - Collections.singleton(sw3Eth1)).anyTimes();
151 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1")))
152 - .andReturn(sw3Eth1).anyTimes();
153 - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
154 - }
155 -
156 - /**
157 - * Tests adding a route. Ingresses with VLAN and next hop with no VLAN.
158 - *
159 - * We verify that the synchronizer records the correct state and that the
160 - * correct intent is submitted to the IntentService.
161 - */
162 - @Test
163 - public void testRouteAdd() {
164 - ResolvedRoute route = new ResolvedRoute(PREFIX1,
165 - Ip4Address.valueOf("192.168.30.1"),
166 - MacAddress.valueOf("00:00:00:00:00:03"));
167 -
168 - // Construct a MultiPointToSinglePointIntent intent
169 - TrafficSelector.Builder selectorBuilder =
170 - DefaultTrafficSelector.builder();
171 - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1)
172 - .matchVlanId(VlanId.ANY);
173 -
174 - TrafficTreatment.Builder treatmentBuilder =
175 - DefaultTrafficTreatment.builder();
176 - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03"))
177 - .setVlanId(VlanId.vlanId((short) 2));
178 -
179 - Set<ConnectPoint> ingressPoints = new HashSet<>();
180 - ingressPoints.add(SW1_ETH1);
181 - ingressPoints.add(SW2_ETH1);
182 -
183 - MultiPointToSinglePointIntent intent =
184 - MultiPointToSinglePointIntent.builder()
185 - .appId(APPID)
186 - .key(Key.of(PREFIX1.toString(), APPID))
187 - .selector(selectorBuilder.build())
188 - .treatment(treatmentBuilder.build())
189 - .ingressPoints(ingressPoints)
190 - .egressPoint(SW3_ETH1)
191 - .constraints(SdnIpFib.CONSTRAINTS)
192 - .build();
193 -
194 - // Setup the expected intents
195 - intentSynchronizer.submit(eqExceptId(intent));
196 - replay(intentSynchronizer);
197 -
198 - // Send in the added event
199 - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
200 -
201 - verify(intentSynchronizer);
202 - }
203 -
204 - private class TestCoreService extends CoreServiceAdapter {
205 - @Override
206 - public ApplicationId getAppId(String name) {
207 - return APPID;
208 - }
209 - }
210 -
211 - private class TestRouteService extends RouteServiceAdapter {
212 - @Override
213 - public void addListener(RouteListener routeListener) {
214 - SdnIpFibVlansToVlanDifferentTest.this.routeListener = routeListener;
215 - }
216 - }
217 -
218 - private class InterfaceServiceDelegate extends InterfaceServiceAdapter {
219 - @Override
220 - public void addListener(InterfaceListener listener) {
221 - SdnIpFibVlansToVlanDifferentTest.this.interfaceListener = listener;
222 - }
223 - }
224 -}
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -package org.onosproject.sdnip;
18 -
19 -import com.google.common.collect.Lists;
20 -import com.google.common.collect.Sets;
21 -import org.junit.Before;
22 -import org.junit.Test;
23 -import org.onlab.packet.Ethernet;
24 -import org.onlab.packet.Ip4Address;
25 -import org.onlab.packet.Ip4Prefix;
26 -import org.onlab.packet.IpPrefix;
27 -import org.onlab.packet.MacAddress;
28 -import org.onlab.packet.VlanId;
29 -import org.onosproject.TestApplicationId;
30 -import org.onosproject.core.ApplicationId;
31 -import org.onosproject.core.CoreServiceAdapter;
32 -import org.onosproject.incubator.net.intf.Interface;
33 -import org.onosproject.incubator.net.intf.InterfaceListener;
34 -import org.onosproject.incubator.net.intf.InterfaceService;
35 -import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
36 -import org.onosproject.incubator.net.routing.ResolvedRoute;
37 -import org.onosproject.incubator.net.routing.RouteEvent;
38 -import org.onosproject.incubator.net.routing.RouteListener;
39 -import org.onosproject.incubator.net.routing.RouteServiceAdapter;
40 -import org.onosproject.net.ConnectPoint;
41 -import org.onosproject.net.DeviceId;
42 -import org.onosproject.net.PortNumber;
43 -import org.onosproject.net.flow.DefaultTrafficSelector;
44 -import org.onosproject.net.flow.DefaultTrafficTreatment;
45 -import org.onosproject.net.flow.TrafficSelector;
46 -import org.onosproject.net.flow.TrafficTreatment;
47 -import org.onosproject.net.host.InterfaceIpAddress;
48 -import org.onosproject.net.intent.AbstractIntentTest;
49 -import org.onosproject.net.intent.Key;
50 -import org.onosproject.net.intent.MultiPointToSinglePointIntent;
51 -import org.onosproject.routing.IntentSynchronizationService;
52 -
53 -import java.util.Collections;
54 -import java.util.HashSet;
55 -import java.util.List;
56 -import java.util.Set;
57 -
58 -import static org.easymock.EasyMock.*;
59 -import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId;
60 -
61 -/**
62 - * Unit tests for SdnIpFib.
63 - */
64 -public class SdnIpFibVlansToVlanSameTest extends AbstractIntentTest {
65 -
66 - private InterfaceService interfaceService;
67 -
68 - private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
69 - DeviceId.deviceId("of:0000000000000001"),
70 - PortNumber.portNumber(1));
71 -
72 - private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
73 - DeviceId.deviceId("of:0000000000000002"),
74 - PortNumber.portNumber(1));
75 -
76 - private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
77 - DeviceId.deviceId("of:0000000000000003"),
78 - PortNumber.portNumber(1));
79 -
80 - private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
81 -
82 - private SdnIpFib sdnipFib;
83 - private IntentSynchronizationService intentSynchronizer;
84 - private final Set<Interface> interfaces = Sets.newHashSet();
85 -
86 - private static final ApplicationId APPID = TestApplicationId.create("SDNIP");
87 -
88 - private RouteListener routeListener;
89 - private InterfaceListener interfaceListener;
90 -
91 - @Before
92 - public void setUp() throws Exception {
93 - super.setUp();
94 -
95 - interfaceService = createMock(InterfaceService.class);
96 -
97 - interfaceService.addListener(anyObject(InterfaceListener.class));
98 - expectLastCall().andDelegateTo(new InterfaceServiceDelegate());
99 -
100 - // These will set expectations on routingConfig and interfaceService
101 - setUpInterfaceService();
102 -
103 - replay(interfaceService);
104 -
105 - intentSynchronizer = createMock(IntentSynchronizationService.class);
106 -
107 - sdnipFib = new SdnIpFib();
108 - sdnipFib.routeService = new TestRouteService();
109 - sdnipFib.coreService = new TestCoreService();
110 - sdnipFib.interfaceService = interfaceService;
111 - sdnipFib.intentSynchronizer = intentSynchronizer;
112 -
113 - sdnipFib.activate();
114 - }
115 -
116 - /**
117 - * Sets up the interface service.
118 - */
119 - private void setUpInterfaceService() {
120 - List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList();
121 - interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24"));
122 - Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1,
123 - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
124 - VlanId.vlanId((short) 1));
125 - interfaces.add(sw1Eth1);
126 -
127 - List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList();
128 - interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24"));
129 - Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1,
130 - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
131 - VlanId.vlanId((short) 1));
132 - interfaces.add(sw2Eth1);
133 -
134 - InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24");
135 - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1,
136 - Lists.newArrayList(interfaceIpAddress3),
137 - MacAddress.valueOf("00:00:00:00:00:03"),
138 - VlanId.vlanId((short) 1));
139 - interfaces.add(sw3Eth1);
140 -
141 - expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
142 - Collections.singleton(sw1Eth1)).anyTimes();
143 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1")))
144 - .andReturn(sw1Eth1).anyTimes();
145 - expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn(
146 - Collections.singleton(sw2Eth1)).anyTimes();
147 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1")))
148 - .andReturn(sw2Eth1).anyTimes();
149 - expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
150 - Collections.singleton(sw3Eth1)).anyTimes();
151 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1")))
152 - .andReturn(sw3Eth1).anyTimes();
153 - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
154 - }
155 -
156 - /**
157 - * Tests adding a route. Ingresses with VLAN and next hop with no VLAN.
158 - *
159 - * We verify that the synchronizer records the correct state and that the
160 - * correct intent is submitted to the IntentService.
161 - */
162 - @Test
163 - public void testRouteAdd() {
164 - ResolvedRoute route = new ResolvedRoute(PREFIX1,
165 - Ip4Address.valueOf("192.168.30.1"),
166 - MacAddress.valueOf("00:00:00:00:00:03"));
167 -
168 - // Construct a MultiPointToSinglePointIntent intent
169 - TrafficSelector.Builder selectorBuilder =
170 - DefaultTrafficSelector.builder();
171 - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1)
172 - .matchVlanId(VlanId.ANY);
173 -
174 - TrafficTreatment.Builder treatmentBuilder =
175 - DefaultTrafficTreatment.builder();
176 - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03"));
177 -
178 - Set<ConnectPoint> ingressPoints = new HashSet<>();
179 - ingressPoints.add(SW1_ETH1);
180 - ingressPoints.add(SW2_ETH1);
181 -
182 - MultiPointToSinglePointIntent intent =
183 - MultiPointToSinglePointIntent.builder()
184 - .appId(APPID)
185 - .key(Key.of(PREFIX1.toString(), APPID))
186 - .selector(selectorBuilder.build())
187 - .treatment(treatmentBuilder.build())
188 - .ingressPoints(ingressPoints)
189 - .egressPoint(SW3_ETH1)
190 - .constraints(SdnIpFib.CONSTRAINTS)
191 - .build();
192 -
193 - // Setup the expected intents
194 - intentSynchronizer.submit(eqExceptId(intent));
195 - replay(intentSynchronizer);
196 -
197 - // Send in the added event
198 - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
199 -
200 - verify(intentSynchronizer);
201 - }
202 -
203 - private class TestCoreService extends CoreServiceAdapter {
204 - @Override
205 - public ApplicationId getAppId(String name) {
206 - return APPID;
207 - }
208 - }
209 -
210 - private class TestRouteService extends RouteServiceAdapter {
211 - @Override
212 - public void addListener(RouteListener routeListener) {
213 - SdnIpFibVlansToVlanSameTest.this.routeListener = routeListener;
214 - }
215 - }
216 -
217 - private class InterfaceServiceDelegate extends InterfaceServiceAdapter {
218 - @Override
219 - public void addListener(InterfaceListener listener) {
220 - SdnIpFibVlansToVlanSameTest.this.interfaceListener = listener;
221 - }
222 - }
223 -}
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -package org.onosproject.sdnip;
18 -
19 -import com.google.common.collect.Lists;
20 -import com.google.common.collect.Sets;
21 -import org.junit.Before;
22 -import org.junit.Test;
23 -import org.onlab.packet.Ethernet;
24 -import org.onlab.packet.Ip4Address;
25 -import org.onlab.packet.Ip4Prefix;
26 -import org.onlab.packet.IpPrefix;
27 -import org.onlab.packet.MacAddress;
28 -import org.onlab.packet.VlanId;
29 -import org.onosproject.TestApplicationId;
30 -import org.onosproject.core.ApplicationId;
31 -import org.onosproject.core.CoreServiceAdapter;
32 -import org.onosproject.incubator.net.intf.Interface;
33 -import org.onosproject.incubator.net.intf.InterfaceListener;
34 -import org.onosproject.incubator.net.intf.InterfaceService;
35 -import org.onosproject.incubator.net.intf.InterfaceServiceAdapter;
36 -import org.onosproject.incubator.net.routing.ResolvedRoute;
37 -import org.onosproject.incubator.net.routing.RouteEvent;
38 -import org.onosproject.incubator.net.routing.RouteListener;
39 -import org.onosproject.incubator.net.routing.RouteServiceAdapter;
40 -import org.onosproject.net.ConnectPoint;
41 -import org.onosproject.net.DeviceId;
42 -import org.onosproject.net.PortNumber;
43 -import org.onosproject.net.flow.DefaultTrafficSelector;
44 -import org.onosproject.net.flow.DefaultTrafficTreatment;
45 -import org.onosproject.net.flow.TrafficSelector;
46 -import org.onosproject.net.flow.TrafficTreatment;
47 -import org.onosproject.net.host.InterfaceIpAddress;
48 -import org.onosproject.net.intent.AbstractIntentTest;
49 -import org.onosproject.net.intent.Key;
50 -import org.onosproject.net.intent.MultiPointToSinglePointIntent;
51 -import org.onosproject.routing.IntentSynchronizationService;
52 -
53 -import java.util.Collections;
54 -import java.util.HashSet;
55 -import java.util.List;
56 -import java.util.Set;
57 -
58 -import static org.easymock.EasyMock.*;
59 -import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId;
60 -
61 -/**
62 - * Unit tests for SdnIpFib.
63 - */
64 -public class SdnIpFibVlanstoNoVlanTest extends AbstractIntentTest {
65 -
66 - private InterfaceService interfaceService;
67 -
68 - private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
69 - DeviceId.deviceId("of:0000000000000001"),
70 - PortNumber.portNumber(1));
71 -
72 - private static final ConnectPoint SW2_ETH1 = new ConnectPoint(
73 - DeviceId.deviceId("of:0000000000000002"),
74 - PortNumber.portNumber(1));
75 -
76 - private static final ConnectPoint SW3_ETH1 = new ConnectPoint(
77 - DeviceId.deviceId("of:0000000000000003"),
78 - PortNumber.portNumber(1));
79 -
80 - private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24");
81 -
82 - private SdnIpFib sdnipFib;
83 - private IntentSynchronizationService intentSynchronizer;
84 - private final Set<Interface> interfaces = Sets.newHashSet();
85 -
86 - private static final ApplicationId APPID = TestApplicationId.create("SDNIP");
87 -
88 - private RouteListener routeListener;
89 - private InterfaceListener interfaceListener;
90 -
91 - @Before
92 - public void setUp() throws Exception {
93 - super.setUp();
94 -
95 - interfaceService = createMock(InterfaceService.class);
96 -
97 - interfaceService.addListener(anyObject(InterfaceListener.class));
98 - expectLastCall().andDelegateTo(new InterfaceServiceDelegate());
99 -
100 - // These will set expectations on routingConfig and interfaceService
101 - setUpInterfaceService();
102 -
103 - replay(interfaceService);
104 -
105 - intentSynchronizer = createMock(IntentSynchronizationService.class);
106 -
107 - sdnipFib = new SdnIpFib();
108 - sdnipFib.routeService = new TestRouteService();
109 - sdnipFib.coreService = new TestCoreService();
110 - sdnipFib.interfaceService = interfaceService;
111 - sdnipFib.intentSynchronizer = intentSynchronizer;
112 -
113 - sdnipFib.activate();
114 - }
115 -
116 - /**
117 - * Sets up the interface service.
118 - */
119 - private void setUpInterfaceService() {
120 - List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList();
121 - interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24"));
122 - Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1,
123 - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
124 - VlanId.vlanId((short) 1));
125 - interfaces.add(sw1Eth1);
126 -
127 - List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList();
128 - interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24"));
129 - Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1,
130 - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
131 - VlanId.vlanId((short) 1));
132 - interfaces.add(sw2Eth1);
133 -
134 - InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24");
135 - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1,
136 - Lists.newArrayList(interfaceIpAddress3),
137 - MacAddress.valueOf("00:00:00:00:00:03"),
138 - VlanId.NONE);
139 - interfaces.add(sw3Eth1);
140 -
141 - expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
142 - Collections.singleton(sw1Eth1)).anyTimes();
143 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1")))
144 - .andReturn(sw1Eth1).anyTimes();
145 - expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn(
146 - Collections.singleton(sw2Eth1)).anyTimes();
147 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1")))
148 - .andReturn(sw2Eth1).anyTimes();
149 - expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
150 - Collections.singleton(sw3Eth1)).anyTimes();
151 - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1")))
152 - .andReturn(sw3Eth1).anyTimes();
153 - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
154 - }
155 -
156 - /**
157 - * Tests adding a route. Ingresses with VLAN and next hop with no VLAN.
158 - *
159 - * We verify that the synchronizer records the correct state and that the
160 - * correct intent is submitted to the IntentService.
161 - */
162 - @Test
163 - public void testRouteAdd() {
164 - ResolvedRoute route = new ResolvedRoute(PREFIX1,
165 - Ip4Address.valueOf("192.168.30.1"),
166 - MacAddress.valueOf("00:00:00:00:00:03"));
167 -
168 - // Construct a MultiPointToSinglePointIntent intent
169 - TrafficSelector.Builder selectorBuilder =
170 - DefaultTrafficSelector.builder();
171 - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1)
172 - .matchVlanId(VlanId.ANY);
173 -
174 - TrafficTreatment.Builder treatmentBuilder =
175 - DefaultTrafficTreatment.builder();
176 - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03"))
177 - .popVlan();
178 -
179 - Set<ConnectPoint> ingressPoints = new HashSet<>();
180 - ingressPoints.add(SW1_ETH1);
181 - ingressPoints.add(SW2_ETH1);
182 -
183 - MultiPointToSinglePointIntent intent =
184 - MultiPointToSinglePointIntent.builder()
185 - .appId(APPID)
186 - .key(Key.of(PREFIX1.toString(), APPID))
187 - .selector(selectorBuilder.build())
188 - .treatment(treatmentBuilder.build())
189 - .ingressPoints(ingressPoints)
190 - .egressPoint(SW3_ETH1)
191 - .constraints(SdnIpFib.CONSTRAINTS)
192 - .build();
193 -
194 - // Setup the expected intents
195 - intentSynchronizer.submit(eqExceptId(intent));
196 - replay(intentSynchronizer);
197 -
198 - // Send in the added event
199 - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
200 -
201 - verify(intentSynchronizer);
202 - }
203 -
204 - private class TestCoreService extends CoreServiceAdapter {
205 - @Override
206 - public ApplicationId getAppId(String name) {
207 - return APPID;
208 - }
209 - }
210 -
211 - private class TestRouteService extends RouteServiceAdapter {
212 - @Override
213 - public void addListener(RouteListener routeListener) {
214 - SdnIpFibVlanstoNoVlanTest.this.routeListener = routeListener;
215 - }
216 - }
217 -
218 - private class InterfaceServiceDelegate extends InterfaceServiceAdapter {
219 - @Override
220 - public void addListener(InterfaceListener listener) {
221 - SdnIpFibVlanstoNoVlanTest.this.interfaceListener = listener;
222 - }
223 - }
224 -}
...@@ -549,7 +549,16 @@ public class NeighbourResolutionManager implements NeighbourResolutionService { ...@@ -549,7 +549,16 @@ public class NeighbourResolutionManager implements NeighbourResolutionService {
549 549
550 @Override 550 @Override
551 public void forward(NeighbourMessageContext context, Interface outIntf) { 551 public void forward(NeighbourMessageContext context, Interface outIntf) {
552 - // TODO implement 552 + Ethernet packetOut = (Ethernet) context.packet().clone();
553 + if (outIntf.vlan().equals(VlanId.NONE)) {
554 + // The egress interface has no VLAN Id. Send out an untagged
555 + // packet
556 + packetOut.setVlanID(Ethernet.VLAN_UNTAGGED);
557 + } else {
558 + // The egress interface has a VLAN set. Send out a tagged packet
559 + packetOut.setVlanID(outIntf.vlan().toShort());
560 + }
561 + sendTo(packetOut, outIntf.connectPoint());
553 } 562 }
554 563
555 @Override 564 @Override
......