Moved ProxyArp, SDN-IP and BgpRouter to use new config format.
The new config format is based on the new network configuration subsystem.
Includes a few config fixes to NetworkConfigLoader and InterfaceManager.
Change-Id: Id7f766736decb7afb6b63c2731d3baba9fc7c764
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
index 2a52539..fc5782e 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/IntentSyncTest.java
@@ -28,6 +28,9 @@
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.incubator.net.intf.Interface;
+import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
@@ -45,7 +48,6 @@
import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.RouteEntry;
import org.onosproject.routing.config.BgpPeer;
-import org.onosproject.routing.config.Interface;
import org.onosproject.routing.config.RoutingConfigurationService;
import org.onosproject.sdnip.IntentSynchronizer.IntentKey;
@@ -56,7 +58,11 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -71,7 +77,9 @@
public class IntentSyncTest extends AbstractIntentTest {
private RoutingConfigurationService routingConfig;
+ private InterfaceService interfaceService;
private IntentService intentService;
+ private NetworkConfigService configService;
private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
DeviceId.deviceId("of:0000000000000001"),
@@ -90,6 +98,7 @@
PortNumber.portNumber(1));
private IntentSynchronizer intentSynchronizer;
+ private final Set<Interface> interfaces = Sets.newHashSet();
private static final ApplicationId APPID = new ApplicationId() {
@Override
@@ -108,17 +117,21 @@
super.setUp();
routingConfig = createMock(RoutingConfigurationService.class);
+ interfaceService = createMock(InterfaceService.class);
+ configService = createMock(NetworkConfigService.class);
// These will set expectations on routingConfig
setUpInterfaceService();
setUpBgpPeers();
replay(routingConfig);
+ replay(interfaceService);
intentService = createMock(IntentService.class);
intentSynchronizer = new IntentSynchronizer(APPID, intentService,
- null, routingConfig);
+ null, routingConfig,
+ interfaceService);
}
/**
@@ -152,9 +165,6 @@
* Sets up InterfaceService.
*/
private void setUpInterfaceService() {
-
- Set<Interface> interfaces = Sets.newHashSet();
-
Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet();
interfaceIpAddresses1.add(new InterfaceIpAddress(
IpAddress.valueOf("192.168.10.101"),
@@ -190,16 +200,26 @@
MacAddress.valueOf("00:00:00:00:00:04"),
VlanId.vlanId((short) 1));
- expect(routingConfig.getInterface(SW4_ETH1)).andReturn(
- sw4Eth1).anyTimes();
+ expect(interfaceService.getInterfacesByPort(SW4_ETH1)).andReturn(
+ Collections.singleton(sw4Eth1)).anyTimes();
+ expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1")))
+ .andReturn(sw4Eth1).anyTimes();
+
interfaces.add(sw4Eth1);
- expect(routingConfig.getInterface(SW1_ETH1)).andReturn(
- sw1Eth1).anyTimes();
- expect(routingConfig.getInterface(SW2_ETH1)).andReturn(
- sw2Eth1).anyTimes();
- expect(routingConfig.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes();
- expect(routingConfig.getInterfaces()).andReturn(interfaces).anyTimes();
+ expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
+ Collections.singleton(sw1Eth1)).anyTimes();
+ expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1")))
+ .andReturn(sw1Eth1).anyTimes();
+ expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn(
+ Collections.singleton(sw2Eth1)).anyTimes();
+ expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1")))
+ .andReturn(sw2Eth1).anyTimes();
+ expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
+ Collections.singleton(sw3Eth1)).anyTimes();
+ expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1")))
+ .andReturn(sw3Eth1).anyTimes();
+ expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
}
/**
@@ -599,8 +619,8 @@
treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress));
Set<ConnectPoint> ingressPoints = new HashSet<>();
- for (Interface intf : routingConfig.getInterfaces()) {
- if (!intf.equals(routingConfig.getInterface(egressPoint))) {
+ for (Interface intf : interfaces) {
+ if (!intf.connectPoint().equals(egressPoint)) {
ConnectPoint srcPort = intf.connectPoint();
ingressPoints.add(srcPort);
}
@@ -621,7 +641,6 @@
* A static MultiPointToSinglePointIntent builder, the returned intent is
* equal to the input intent except that the id is different.
*
- *
* @param intent the intent to be used for building a new intent
* @param routeEntry the relative routeEntry of the intent
* @return the newly constructed MultiPointToSinglePointIntent
diff --git a/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java b/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
index 19c1d50..164b54d 100644
--- a/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
+++ b/apps/sdnip/src/test/java/org/onosproject/sdnip/PeerConnectivityManagerTest.java
@@ -29,6 +29,9 @@
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.incubator.net.intf.Interface;
+import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
@@ -41,9 +44,9 @@
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.PointToPointIntent;
+import org.onosproject.routing.config.BgpConfig;
import org.onosproject.routing.config.BgpPeer;
import org.onosproject.routing.config.BgpSpeaker;
-import org.onosproject.routing.config.Interface;
import org.onosproject.routing.config.InterfaceAddress;
import org.onosproject.routing.config.RoutingConfigurationService;
@@ -53,6 +56,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
@@ -78,16 +82,21 @@
}
};
+ private static final ApplicationId CONFIG_APP_ID = APPID;
+
private PeerConnectivityManager peerConnectivityManager;
private IntentSynchronizer intentSynchronizer;
private RoutingConfigurationService routingConfig;
+ private InterfaceService interfaceService;
+ private NetworkConfigService networkConfigService;
private IntentService intentService;
- private Map<String, BgpSpeaker> bgpSpeakers;
+ private Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers;
private Map<String, Interface> interfaces;
private Map<IpAddress, BgpPeer> peers;
- private Map<String, BgpSpeaker> configuredBgpSpeakers;
+ private BgpConfig bgpConfig;
+
private Map<String, Interface> configuredInterfaces;
private Map<IpAddress, BgpPeer> configuredPeers;
private List<PointToPointIntent> intentList;
@@ -119,9 +128,12 @@
public void setUp() throws Exception {
super.setUp();
routingConfig = createMock(RoutingConfigurationService.class);
+ interfaceService = createMock(InterfaceService.class);
+ networkConfigService = createMock(NetworkConfigService.class);
+ bgpConfig = createMock(BgpConfig.class);
- // These will set expectations on routingConfig
- bgpSpeakers = Collections.unmodifiableMap(setUpBgpSpeakers());
+ // These will set expectations on routingConfig and interfaceService
+ bgpSpeakers = setUpBgpSpeakers();
interfaces = Collections.unmodifiableMap(setUpInterfaces());
peers = Collections.unmodifiableMap(setUpPeers());
@@ -134,31 +146,20 @@
*
* @return configured BGP speakers as a map from speaker name to speaker
*/
- private Map<String, BgpSpeaker> setUpBgpSpeakers() {
+ private Set<BgpConfig.BgpSpeakerConfig> setUpBgpSpeakers() {
- configuredBgpSpeakers = new HashMap<>();
+ BgpConfig.BgpSpeakerConfig speaker1 = new BgpConfig.BgpSpeakerConfig(
+ s1Eth100, Collections.singleton(IpAddress.valueOf("192.168.10.1")));
- BgpSpeaker bgpSpeaker1 = new BgpSpeaker(
- "bgpSpeaker1",
- "00:00:00:00:00:00:00:01", 100,
- "00:00:00:00:00:01");
- List<InterfaceAddress> interfaceAddresses1 = new LinkedList<>();
- interfaceAddresses1.add(new InterfaceAddress(dpid1, 1, "192.168.10.101"));
- bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1);
- configuredBgpSpeakers.put(bgpSpeaker1.name(), bgpSpeaker1);
+ BgpConfig.BgpSpeakerConfig speaker2 = new BgpConfig.BgpSpeakerConfig(
+ s1Eth100, Sets.newHashSet(IpAddress.valueOf("192.168.20.1"),
+ IpAddress.valueOf("192.168.30.1")));
- // BGP speaker2 is attached to the same switch port with speaker1
- BgpSpeaker bgpSpeaker2 = new BgpSpeaker(
- "bgpSpeaker2",
- "00:00:00:00:00:00:00:01", 100,
- "00:00:00:00:00:02");
- List<InterfaceAddress> interfaceAddresses2 = new LinkedList<>();
- interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.20.101"));
- interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.30.101"));
- bgpSpeaker2.setInterfaceAddresses(interfaceAddresses2);
- configuredBgpSpeakers.put(bgpSpeaker2.name(), bgpSpeaker2);
+ Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers = Sets.newHashSet();
+ bgpSpeakers.add(speaker1);
+ bgpSpeakers.add(speaker2);
- return configuredBgpSpeakers;
+ return bgpSpeakers;
}
/**
@@ -201,26 +202,31 @@
VlanId.NONE);
configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2);
- expect(routingConfig.getInterface(s1Eth1))
+ expect(interfaceService.getInterfacesByPort(s1Eth1))
+ .andReturn(Collections.singleton(intfsw1eth1)).anyTimes();
+ expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101")))
+ .andReturn(Collections.singleton(intfsw1eth1)).anyTimes();
+ expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1")))
.andReturn(intfsw1eth1).anyTimes();
- expect(routingConfig.getInterface(IpAddress.valueOf("192.168.10.101")))
- .andReturn(intfsw1eth1).anyTimes();
- expect(routingConfig.getInterface(s2Eth1))
+ expect(interfaceService.getInterfacesByPort(s2Eth1))
+ .andReturn(Collections.singleton(intfsw2eth1)).anyTimes();
+ expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101")))
+ .andReturn(Collections.singleton(intfsw2eth1)).anyTimes();
+ expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.20.1")))
.andReturn(intfsw2eth1).anyTimes();
- expect(routingConfig.getInterface(IpAddress.valueOf("192.168.20.101")))
- .andReturn(intfsw2eth1).anyTimes();
- //expect(routingConfig.getInterface(s2Eth1))
- // .andReturn(intfsw2eth1intf2).anyTimes();
- expect(routingConfig.getInterface(IpAddress.valueOf("192.168.30.101")))
+
+ expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.30.101")))
+ .andReturn(Collections.singleton(intfsw2eth1intf2)).anyTimes();
+ expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1")))
.andReturn(intfsw2eth1intf2).anyTimes();
// Non-existent interface used during one of the tests
- expect(routingConfig.getInterface(new ConnectPoint(
- DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")),
- PortNumber.portNumber(1))))
+ expect(interfaceService.getInterfacesByPort(new ConnectPoint(
+ DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")),
+ PortNumber.portNumber(1))))
.andReturn(null).anyTimes();
- expect(routingConfig.getInterfaces()).andReturn(
+ expect(interfaceService.getInterfaces()).andReturn(
Sets.newHashSet(configuredInterfaces.values())).anyTimes();
return configuredInterfaces;
@@ -398,7 +404,6 @@
* Sets up intents for ICMP paths.
*/
private void setUpIcmpIntents() {
-
// Start to build intents between BGP speaker1 and BGP peer1
icmpPathintentConstructor(
"192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1);
@@ -415,7 +420,6 @@
"192.168.30.101/32", "192.168.30.1/32", s1Eth100, s2Eth1);
icmpPathintentConstructor(
"192.168.30.1/32", "192.168.30.101/32", s2Eth1, s1Eth100);
-
}
/**
@@ -424,22 +428,28 @@
* @throws TestUtilsException if exceptions when using TestUtils
*/
private void initPeerConnectivity() throws TestUtilsException {
-
expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
- expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
+ expect(bgpConfig.bgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
+ replay(bgpConfig);
+ expect(networkConfigService.getConfig(APPID, BgpConfig.class)).andReturn(bgpConfig).anyTimes();
+ replay(networkConfigService);
replay(routingConfig);
+ replay(interfaceService);
intentService = createMock(IntentService.class);
replay(intentService);
intentSynchronizer = new IntentSynchronizer(APPID, intentService,
- null, routingConfig);
+ null, routingConfig,
+ interfaceService);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
peerConnectivityManager =
new PeerConnectivityManager(APPID, intentSynchronizer,
- routingConfig);
+ networkConfigService,
+ CONFIG_APP_ID,
+ interfaceService);
}
/**
@@ -472,42 +482,28 @@
*/
@Test
public void testNullInterfaces() {
- reset(routingConfig);
- expect(routingConfig.getInterfaces()).andReturn(
+ reset(interfaceService);
+
+ expect(interfaceService.getInterfaces()).andReturn(
Sets.<Interface>newHashSet()).anyTimes();
- expect(routingConfig.getInterface(s2Eth1))
+ expect(interfaceService.getInterfacesByPort(s2Eth1))
+ .andReturn(Collections.emptySet()).anyTimes();
+ expect(interfaceService.getInterfacesByPort(s1Eth1))
+ .andReturn(Collections.emptySet()).anyTimes();
+ expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101")))
+ .andReturn(Collections.emptySet()).anyTimes();
+ expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1")))
.andReturn(null).anyTimes();
- expect(routingConfig.getInterface(s1Eth1))
- .andReturn(null).anyTimes();
- expect(routingConfig.getInterface(IpAddress.valueOf("192.168.10.101")))
+ expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101")))
+ .andReturn(Collections.emptySet()).anyTimes();
+ expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.20.1")))
.andReturn(null).anyTimes();
- expect(routingConfig.getInterface(IpAddress.valueOf("192.168.20.101")))
- .andReturn(null).anyTimes();
- expect(routingConfig.getInterface(IpAddress.valueOf("192.168.30.101")))
+ expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.30.101")))
+ .andReturn(Collections.emptySet()).anyTimes();
+ expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1")))
.andReturn(null).anyTimes();
- expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
- expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
- replay(routingConfig);
-
- reset(intentService);
- replay(intentService);
- peerConnectivityManager.start();
- verify(intentService);
- }
-
- /**
- * Tests a corner case, when there are no BGP peers in the configuration.
- */
- @Test
- public void testNullBgpPeers() {
- reset(routingConfig);
- expect(routingConfig.getInterfaces()).andReturn(
- Sets.newHashSet(interfaces.values())).anyTimes();
-
- expect(routingConfig.getBgpPeers()).andReturn(new HashMap<>()).anyTimes();
- expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
- replay(routingConfig);
+ replay(interfaceService);
reset(intentService);
replay(intentService);
@@ -521,12 +517,11 @@
@Test
public void testNullBgpSpeakers() {
reset(routingConfig);
- expect(routingConfig.getInterfaces()).andReturn(
- Sets.newHashSet(interfaces.values())).anyTimes();
+ reset(bgpConfig);
+ expect(bgpConfig.bgpSpeakers()).andReturn(Collections.emptySet()).anyTimes();
+ replay(bgpConfig);
expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
- expect(routingConfig.getBgpSpeakers()).andReturn(
- Collections.emptyMap()).anyTimes();
replay(routingConfig);
reset(intentService);
@@ -562,7 +557,6 @@
interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201"));
interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201"));
bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100);
- configuredBgpSpeakers.put(bgpSpeaker100.name(), bgpSpeaker100);
testConnectionSetup();
}
}