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;
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
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
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
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
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);
}
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);
@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);
.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
.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
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
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);
}
}