CORD-508 SegmentRouting / vRouter integration
- Added excludePorts config to SegmentRouting
SR does not push VLAN filtering rule to excluded ports
SR ignores hosts learned from excluded ports
- Use separate default route config
Don't need to config 0/0 on the interface anymore
Change-Id: Iea75d60c2d5f5368e79652b1bf192a6ced49030d
diff --git a/apps/segmentrouting/src/test/java/org/onosproject/segmentrouting/config/SegmentRoutingAppConfigTest.java b/apps/segmentrouting/src/test/java/org/onosproject/segmentrouting/config/SegmentRoutingAppConfigTest.java
index 7755059..8acef5c 100644
--- a/apps/segmentrouting/src/test/java/org/onosproject/segmentrouting/config/SegmentRoutingAppConfigTest.java
+++ b/apps/segmentrouting/src/test/java/org/onosproject/segmentrouting/config/SegmentRoutingAppConfigTest.java
@@ -24,6 +24,7 @@
import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.TestApplicationId;
+import org.onosproject.net.DeviceId;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.ConfigApplyDelegate;
import org.onosproject.segmentrouting.SegmentRoutingService;
@@ -32,6 +33,7 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
/**
* Tests for class {@link SegmentRoutingAppConfig}.
@@ -41,9 +43,34 @@
new TestApplicationId(SegmentRoutingService.SR_APP_ID);
private SegmentRoutingAppConfig config;
- private MacAddress routerMac1;
- private MacAddress routerMac2;
- private MacAddress routerMac3;
+ private SegmentRoutingAppConfig invalidConfig;
+ private static final String JSON_STRING = "{" +
+ "\"vRouterMacs\" : [" +
+ " \"00:00:00:00:00:01\"," +
+ " \"00:00:00:00:00:02\"" +
+ "]," +
+ "\"vRouterId\" : \"of:1\"," +
+ "\"excludePorts\" : [" +
+ " \"port1\"," +
+ " \"port2\"" +
+ "]}";
+ private static final String INVALID_JSON_STRING = "{" +
+ "\"vRouterMacs\" : [" +
+ " \"00:00:00:00:00:01\"," +
+ " \"00:00:00:00:00:02\"" +
+ "]," +
+ "\"excludePorts\" : [" +
+ " \"port1\"," +
+ " \"port2\"" +
+ "]}";
+ private static final MacAddress ROUTER_MAC_1 = MacAddress.valueOf("00:00:00:00:00:01");
+ private static final MacAddress ROUTER_MAC_2 = MacAddress.valueOf("00:00:00:00:00:02");
+ private static final MacAddress ROUTER_MAC_3 = MacAddress.valueOf("00:00:00:00:00:03");
+ private static final String PORT_NAME_1 = "port1";
+ private static final String PORT_NAME_2 = "port2";
+ private static final String PORT_NAME_3 = "port3";
+ private static final DeviceId VROUTER_ID_1 = DeviceId.deviceId("of:1");
+ private static final DeviceId VROUTER_ID_2 = DeviceId.deviceId("of:2");
/**
* Initialize test related variables.
@@ -52,55 +79,107 @@
*/
@Before
public void setUp() throws Exception {
- String jsonString = "{" +
- "\"vRouterMacs\" : [" +
- " \"00:00:00:00:00:01\"," +
- " \"00:00:00:00:00:02\"" +
- "]}";
-
- routerMac1 = MacAddress.valueOf("00:00:00:00:00:01");
- routerMac2 = MacAddress.valueOf("00:00:00:00:00:02");
- routerMac3 = MacAddress.valueOf("00:00:00:00:00:03");
-
ApplicationId subject = APP_ID;
String key = SegmentRoutingService.SR_APP_ID;
ObjectMapper mapper = new ObjectMapper();
- JsonNode jsonNode = mapper.readTree(jsonString);
+ JsonNode jsonNode = mapper.readTree(JSON_STRING);
+ JsonNode invalidJsonNode = mapper.readTree(INVALID_JSON_STRING);
ConfigApplyDelegate delegate = new MockDelegate();
config = new SegmentRoutingAppConfig();
config.init(subject, key, jsonNode, mapper, delegate);
+ invalidConfig = new SegmentRoutingAppConfig();
+ invalidConfig.init(subject, key, invalidJsonNode, mapper, delegate);
}
/**
- * Tests vRouters getter.
+ * Tests config validity.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testIsValid() throws Exception {
+ assertTrue(config.isValid());
+ assertFalse(invalidConfig.isValid());
+ }
+
+ /**
+ * Tests vRouterMacs getter.
*
* @throws Exception
*/
@Test
public void testVRouters() throws Exception {
- assertTrue(config.isValid());
-
Set<MacAddress> vRouters = config.vRouterMacs();
assertThat(vRouters.size(), is(2));
- assertTrue(vRouters.contains(routerMac1));
- assertTrue(vRouters.contains(routerMac2));
+ assertTrue(vRouters.contains(ROUTER_MAC_1));
+ assertTrue(vRouters.contains(ROUTER_MAC_2));
}
/**
- * Tests vRouters setter.
+ * Tests vRouterMacs setter.
*
* @throws Exception
*/
@Test
public void testSetVRouters() throws Exception {
ImmutableSet.Builder<MacAddress> builder = ImmutableSet.builder();
- builder.add(routerMac3);
+ builder.add(ROUTER_MAC_3);
config.setVRouterMacs(builder.build());
Set<MacAddress> macs = config.vRouterMacs();
assertThat(macs.size(), is(1));
- assertTrue(macs.contains(routerMac3));
+ assertTrue(macs.contains(ROUTER_MAC_3));
+ }
+
+ /**
+ * Tests vRouterId getter.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testVRouterId() throws Exception {
+ assertThat(config.vRouterId(), is(VROUTER_ID_1));
+ }
+
+ /**
+ * Tests vRouterId setter.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testSetVRouterId() throws Exception {
+ config.setVRouterId(VROUTER_ID_2);
+ assertThat(config.vRouterId(), is(VROUTER_ID_2));
+ }
+
+ /**
+ * Tests excludePort getter.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testExcludePorts() throws Exception {
+ Set<String> excludePorts = config.excludePorts();
+ assertThat(excludePorts.size(), is(2));
+ assertTrue(excludePorts.contains(PORT_NAME_1));
+ assertTrue(excludePorts.contains(PORT_NAME_2));
+ }
+
+ /**
+ * Tests excludePort setter.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testSetExcludePorts() throws Exception {
+ ImmutableSet.Builder<String> builder = ImmutableSet.builder();
+ builder.add(PORT_NAME_3);
+ config.setExcludePorts(builder.build());
+
+ Set<String> excludePorts = config.excludePorts();
+ assertThat(excludePorts.size(), is(1));
+ assertTrue(excludePorts.contains(PORT_NAME_3));
}
private class MockDelegate implements ConfigApplyDelegate {