Bug 5617: OfOverlay Refactoring - Destination mapper
[groupbasedpolicy.git] / renderers / ofoverlay / src / test / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / mapper / portsecurity / PortSecurityFlowsTest.java
index e4d7e45e69c0da5dddb9c38311fd04ca01b91581..76fc292e2981bfb7475c0f34d1f91eca8c69da1a 100644 (file)
@@ -9,7 +9,6 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.MapperUtilsTe
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
@@ -33,28 +32,23 @@ import static org.mockito.Mockito.*;
 
 public class PortSecurityFlowsTest extends MapperUtilsTest {
 
-    private static final String DROP_ALL = "dropAll";
-    private static final String DROP = "drop";
-    private static final String ALLOW = "allow";
     private static final String L3 = "L3";
     private static final String DHCP = "dhcp";
-    private static final String ALLOW_EXTERNAL = "allowExternal";
-    private static final String ALLOW_EXTERNAL_POP_VLAN = "allowExternalPopVlan";
     private PortSecurityFlows flows;
 
     @Before
     public void init() {
         tableId = 0;
         ofWriter = mock(OfWriter.class);
-        flows = new PortSecurityFlows(nodeId, tableId);
+        flows = new PortSecurityFlows(NODE_ID, tableId);
     }
 
     @Test
     public void testDropFlow_noEthertype() {
-        Flow testFlow = flowBuilder(new FlowId(DROP_ALL), tableId, 100, null, FlowUtils.dropInstructions()).build();
+        Flow testFlow = buildFlow(new FlowId(DROP_ALL), tableId, 100, null, FlowUtils.dropInstructions()).build();
 
         flows.dropFlow(100, null, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
@@ -62,11 +56,11 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
         MatchBuilder matchBuilder = new MatchBuilder();
         matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv4));
         Match match = matchBuilder.build();
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
                 FlowUtils.dropInstructions()).build();
 
         flows.dropFlow(100, FlowUtils.IPv4, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
@@ -74,11 +68,11 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
         MatchBuilder matchBuilder = new MatchBuilder();
         matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.IPv6));
         Match match = matchBuilder.build();
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
                 FlowUtils.dropInstructions()).build();
 
         flows.dropFlow(100, FlowUtils.IPv6, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
@@ -86,11 +80,11 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
         MatchBuilder matchBuilder = new MatchBuilder();
         matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(null, null, FlowUtils.ARP));
         Match match = matchBuilder.build();
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, DROP, match), tableId, 100, match,
                 FlowUtils.dropInstructions()).build();
 
         flows.dropFlow(100, FlowUtils.ARP, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
@@ -99,11 +93,11 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
         MatchBuilder matchBuilder = new MatchBuilder();
         matchBuilder.setInPort(new NodeConnectorId(String.valueOf(VXLAN_PORT)));
         Match match = matchBuilder.build();
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, ALLOW, match), tableId, 300, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, ALLOW, match), tableId, 300, match,
                 FlowUtils.gotoTableInstructions((short) 2)).build();
 
         flows.allowFromTunnelFlow((short) 2, 300, new NodeConnectorId(CONNECTOR_0), ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
 
     }
 
@@ -113,83 +107,71 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
         MatchBuilder matchBuilder = new MatchBuilder();
         matchBuilder.setInPort(new NodeConnectorId(String.valueOf(VXLAN_PORT)));
         Match match = matchBuilder.build();
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, ALLOW, match), tableId, 300, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, ALLOW, match), tableId, 300, match,
                 FlowUtils.gotoTableInstructions((short) 2)).build();
 
         flows.allowFromTunnelFlow((short) 2, 300, new NodeConnectorId(CONNECTOR_1), ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
 
     }
 
     @Test
     public void testL3flow_ipv4() {
-        IpAddress ipAddress = new IpAddress(new Ipv4Address(IPV4_1));
-        MacAddress macAddress = new MacAddress(MAC_0);
-        NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_0);
-        Endpoint testEp = endpointBuilder(ipAddress, macAddress, connectorId, null, null).build();
+        Endpoint testEp = buildEndpoint(IPV4_0, MAC_0, CONNECTOR_0).build();
 
         MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(macAddress, null, FlowUtils.IPv4))
+        matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(MAC_0, null, FlowUtils.IPv4))
                 .setLayer3Match(new Ipv4MatchBuilder()
-                        .setIpv4Source(new Ipv4Prefix(ipAddress.getIpv4Address().getValue() + IP_PREFIX_32)).build())
-                .setInPort(connectorId);
+                        .setIpv4Source(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32)).build())
+                .setInPort(new NodeConnectorId(CONNECTOR_0));
         Match match = matchBuilder.build();
 
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
                 FlowUtils.gotoTableInstructions((short) 2)).build();
 
         flows.l3Flow((short) 2, testEp, new NodeConnectorId(CONNECTOR_0), new MacAddress(MAC_0), 100, false, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
     public void testL3flow_ipv4Arp() {
-        IpAddress ipAddress = new IpAddress(new Ipv4Address(IPV4_1));
-        MacAddress macAddress = new MacAddress(MAC_1);
-        NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_1);
-        Endpoint testEp = endpointBuilder(ipAddress, macAddress, connectorId, null, null).build();
+        Endpoint testEp = buildEndpoint(IPV4_0, MAC_1, CONNECTOR_1).build();
 
         MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(macAddress, null, FlowUtils.ARP))
-                .setLayer3Match(new ArpMatchBuilder().setArpSourceTransportAddress(new Ipv4Prefix(ipAddress
-                        .getIpv4Address().getValue() + IP_PREFIX_32)).build())
-                .setInPort(connectorId);
+        matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(MAC_1, null, FlowUtils.ARP))
+                .setLayer3Match(new ArpMatchBuilder().setArpSourceTransportAddress(new Ipv4Prefix(IPV4_0.getValue()
+                        + IP_PREFIX_32)).build())
+                .setInPort(new NodeConnectorId(CONNECTOR_1));
         Match match = matchBuilder.build();
 
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
                 FlowUtils.gotoTableInstructions((short) 2)).build();
 
         flows.l3Flow((short) 2, testEp, new NodeConnectorId(CONNECTOR_1), new MacAddress(MAC_1), 100, true, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
     public void testL3flow_ipv6() {
-        IpAddress ipAddress = new IpAddress(new Ipv6Address(IPV6_1));
-        MacAddress macAddress = new MacAddress(MAC_0);
-        NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_0);
-        Endpoint testEp = endpointBuilder(ipAddress, macAddress, connectorId, null, null).build();
+        Endpoint testEp = buildEndpoint(IPV6_1, MAC_0, CONNECTOR_0).build();
 
         MatchBuilder matchBuilder = new MatchBuilder();
-        matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(macAddress, null, FlowUtils.IPv6))
+        matchBuilder.setEthernetMatch(FlowUtils.ethernetMatch(MAC_0, null, FlowUtils.IPv6))
                 .setLayer3Match(new Ipv6MatchBuilder()
-                        .setIpv6Source(new Ipv6Prefix(ipAddress.getIpv6Address().getValue() + IP_PREFIX_128)).build())
-                .setInPort(connectorId);
+                        .setIpv6Source(new Ipv6Prefix(IPV6_1.getValue() + IP_PREFIX_128)).build())
+                .setInPort(new NodeConnectorId(CONNECTOR_0));
         Match match = matchBuilder.build();
 
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, L3, match), tableId, 100, match,
                 FlowUtils.gotoTableInstructions((short) 2)).build();
 
         flows.l3Flow((short) 2, testEp, new NodeConnectorId(CONNECTOR_0), new MacAddress(MAC_0), 100, false, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
     public void testL3flow_ipv6Arp() {
-        IpAddress ipAddress = new IpAddress(new Ipv6Address(IPV6_1));
-        MacAddress macAddress = new MacAddress(MAC_1);
-        NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_1);
-        Endpoint testEp = endpointBuilder(ipAddress, macAddress, connectorId, null, null).build();
+        Endpoint testEp = buildEndpoint(IPV6_1, MAC_1, CONNECTOR_1).build();
 
         flows.l3Flow((short) 2, testEp, new NodeConnectorId(CONNECTOR_1), new MacAddress(MAC_1), 100, true, ofWriter);
         verifyZeroInteractions(ofWriter);
@@ -197,7 +179,7 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
 
     @Test
     public void testL3DhcpDoraFlow() {
-        IpAddress ipAddress = new IpAddress(new Ipv4Address(DHCP_IP));
+        IpAddress ipAddress = new IpAddress(new Ipv4Address("255.255.255.255"));
         MacAddress macAddress = new MacAddress(MAC_1);
         NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_1);
 
@@ -208,11 +190,11 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
                 .setInPort(connectorId);
         Match match = matchBuilder.build();
 
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, DHCP, match), tableId, 50, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, DHCP, match), tableId, 50, match,
                 FlowUtils.gotoTableInstructions((short) 2)).build();
 
         flows.l3DhcpDoraFlow((short) 2, new NodeConnectorId(CONNECTOR_1), new MacAddress(MAC_1), 50, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
@@ -225,11 +207,11 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
                 .setInPort(connectorId);
         Match match = matchBuilder.build();
 
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, L2, match), tableId, 100, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, L2, match), tableId, 100, match,
                 FlowUtils.gotoTableInstructions((short) 2)).build();
 
         flows.l2flow((short) 2, new NodeConnectorId(CONNECTOR_0), new MacAddress(MAC_0), 100, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
@@ -248,13 +230,13 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         instructionsBuilder.setInstruction(instructions);
 
-        List<L2FloodDomain> l2FloodDomains = l2FloodDomains();
+        List<L2FloodDomain> l2FloodDomains = getL2FloodDomainList(false);
 
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, ALLOW_EXTERNAL_POP_VLAN, match), tableId, 200, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, "allowExternalPopVlan", match), tableId, 200, match,
                 instructionsBuilder.build()).build();
 
         flows.popVlanTagsOnExternalPortFlows((short) 0, connectorId, l2FloodDomains, 200, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 
     @Test
@@ -265,9 +247,9 @@ public class PortSecurityFlowsTest extends MapperUtilsTest {
         matchBuilder.setInPort(connectorId);
         Match match = matchBuilder.build();
 
-        Flow testFlow = flowBuilder(FlowIdUtils.newFlowId(tableId, ALLOW_EXTERNAL, match), tableId, 250, match,
+        Flow testFlow = buildFlow(FlowIdUtils.newFlowId(tableId, "allowExternal", match), tableId, 250, match,
                 FlowUtils.gotoTableInstructions((short) 2)).build();
         flows.allowFromExternalPortFlow((short) 2, connectorId, 250, ofWriter);
-        verify(ofWriter, times(1)).writeFlow(nodeId, tableId, testFlow);
+        verify(ofWriter, times(1)).writeFlow(NODE_ID, tableId, testFlow);
     }
 }