Search in sources :

Example 6 with MatchesBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder in project netvirt by opendaylight.

the class AclMatchesTest method buildIpv6MatchTest.

@Test
public void buildIpv6MatchTest() {
    AceIpv6Builder aceIpv6 = new AceIpv6Builder();
    aceIpv6.setDestinationIpv6Network(new Ipv6Prefix(IPV6_DST_STR));
    aceIpv6.setSourceIpv6Network(new Ipv6Prefix(IPV6_SRC_STR));
    AceIpBuilder aceIpBuilder = new AceIpBuilder();
    aceIpBuilder.setAceIpVersion(aceIpv6.build());
    MatchesBuilder matchesBuilder = new MatchesBuilder();
    matchesBuilder.setAceType(aceIpBuilder.build());
    // Create the aclMatches that is the object to be tested
    AclMatches aclMatches = new AclMatches(matchesBuilder.build());
    MatchBuilder matchBuilder = aclMatches.buildMatch();
    // The layer3 match should be there with src/dst values
    Ipv6Match l3 = (Ipv6Match) matchBuilder.getLayer3Match();
    assertNotNull(l3);
    assertEquals(l3.getIpv6Destination().getValue().toString(), IPV6_DST_STR);
    assertEquals(l3.getIpv6Source().getValue().toString(), IPV6_SRC_STR);
    // There should be an IPv6 etherType set
    EthernetMatch ethMatch = matchBuilder.getEthernetMatch();
    assertNotNull(ethMatch);
    assertEquals(ethMatch.getEthernetType().getType().getValue(), Long.valueOf(NwConstants.ETHTYPE_IPV6));
    // The rest should be null
    assertNull(matchBuilder.getIpMatch());
    assertNull(matchBuilder.getLayer4Match());
}
Also used : AceIpv6Builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6Builder) EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) AceIpBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder) Ipv6Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match) MatchesBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix) Test(org.junit.Test)

Example 7 with MatchesBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder in project netvirt by opendaylight.

the class AclMatchesTest method buildEthMatchTest.

@Test
public void buildEthMatchTest() {
    AceEthBuilder aceEthBuilder = new AceEthBuilder();
    aceEthBuilder.setDestinationMacAddress(new MacAddress(MAC_DST_STR));
    aceEthBuilder.setSourceMacAddress(new MacAddress(MAC_SRC_STR));
    MatchesBuilder matchesBuilder = new MatchesBuilder();
    matchesBuilder.setAceType(aceEthBuilder.build());
    // Create the aclMatches that is the object to be tested
    AclMatches aclMatches = new AclMatches(matchesBuilder.build());
    MatchBuilder matchBuilder = aclMatches.buildMatch();
    // The ethernet match should be there with src/dst values
    EthernetMatch ethMatch = matchBuilder.getEthernetMatch();
    assertNotNull(ethMatch);
    assertEquals(ethMatch.getEthernetSource().getAddress().getValue(), MAC_SRC_STR);
    assertEquals(ethMatch.getEthernetDestination().getAddress().getValue(), MAC_DST_STR);
    // The rest should be null
    assertNull(matchBuilder.getIpMatch());
    assertNull(matchBuilder.getLayer3Match());
    assertNull(matchBuilder.getLayer4Match());
}
Also used : EthernetMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch) AceEthBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceEthBuilder) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchesBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) Test(org.junit.Test)

Example 8 with MatchesBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder in project netvirt by opendaylight.

the class AclMatchesTest method invertIpv6MatchTest.

@Test
public void invertIpv6MatchTest() {
    AceIpBuilder aceIpBuilder = new AceIpBuilder();
    aceIpBuilder.setProtocol(IPProtocols.TCP.shortValue());
    aceIpBuilder.setDscp(new Dscp(DSCP_VALUE));
    SourcePortRangeBuilder srcPortRange = new SourcePortRangeBuilder();
    srcPortRange.setLowerPort(new PortNumber(TCP_SRC_LOWER_PORT));
    srcPortRange.setUpperPort(new PortNumber(TCP_SRC_UPPER_PORT));
    SourcePortRange sourcePortRange = srcPortRange.build();
    aceIpBuilder.setSourcePortRange(sourcePortRange);
    DestinationPortRangeBuilder dstPortRange = new DestinationPortRangeBuilder();
    dstPortRange.setLowerPort(new PortNumber(TCP_DST_LOWER_PORT));
    dstPortRange.setUpperPort(new PortNumber(TCP_DST_UPPER_PORT));
    DestinationPortRange destinationPortRange = dstPortRange.build();
    aceIpBuilder.setDestinationPortRange(destinationPortRange);
    AceIpv6Builder aceIpv6Builder = new AceIpv6Builder();
    aceIpv6Builder.setDestinationIpv6Network(new Ipv6Prefix(IPV6_DST_STR));
    aceIpv6Builder.setSourceIpv6Network(new Ipv6Prefix(IPV6_SRC_STR));
    AceIpv6 aceIpv6 = aceIpv6Builder.build();
    aceIpBuilder.setAceIpVersion(aceIpv6);
    MatchesBuilder matchesBuilder = new MatchesBuilder();
    AceIp aceIp = aceIpBuilder.build();
    matchesBuilder.setAceType(aceIp);
    Matches matches = matchesBuilder.build();
    Matches invertedMatches = AclMatches.invertMatches(matches);
    assertNotEquals(matches, invertedMatches);
    AceIp invertedAceIp = (AceIp) invertedMatches.getAceType();
    assertEquals(invertedAceIp.getDscp(), aceIp.getDscp());
    assertEquals(invertedAceIp.getProtocol(), aceIp.getProtocol());
    DestinationPortRange invertedDestinationPortRange = invertedAceIp.getDestinationPortRange();
    assertEquals(invertedDestinationPortRange.getLowerPort(), sourcePortRange.getLowerPort());
    assertEquals(invertedDestinationPortRange.getUpperPort(), sourcePortRange.getUpperPort());
    SourcePortRange invertedSourcePortRange = invertedAceIp.getSourcePortRange();
    assertEquals(invertedSourcePortRange.getLowerPort(), destinationPortRange.getLowerPort());
    assertEquals(invertedSourcePortRange.getUpperPort(), destinationPortRange.getUpperPort());
    AceIpv6 invertedAceIpv6 = (AceIpv6) invertedAceIp.getAceIpVersion();
    assertEquals(invertedAceIpv6.getDestinationIpv6Network(), aceIpv6.getSourceIpv6Network());
    assertEquals(invertedAceIpv6.getSourceIpv6Network(), aceIpv6.getDestinationIpv6Network());
}
Also used : AceIpv6Builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6Builder) SourcePortRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.SourcePortRange) Matches(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches) AceIp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp) MatchesBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder) Ipv6Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix) DestinationPortRange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRange) DestinationPortRangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRangeBuilder) AceIpBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder) Dscp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) AceIpv6(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6) SourcePortRangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.SourcePortRangeBuilder) Test(org.junit.Test)

Example 9 with MatchesBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder in project netvirt by opendaylight.

the class AclMatchesTest method invertEthMatchTest.

@Test
public void invertEthMatchTest() {
    AceEthBuilder aceEthBuilder = new AceEthBuilder();
    aceEthBuilder.setDestinationMacAddress(new MacAddress(MAC_DST_STR));
    aceEthBuilder.setSourceMacAddress(new MacAddress(MAC_SRC_STR));
    AceEth aceEth = aceEthBuilder.build();
    MatchesBuilder matchesBuilder = new MatchesBuilder();
    matchesBuilder.setAceType(aceEth);
    Matches matches = matchesBuilder.build();
    Matches invertedMatches = AclMatches.invertMatches(matches);
    assertNotEquals(matches, invertedMatches);
    AceEth invertedAceEth = (AceEth) invertedMatches.getAceType();
    assertEquals(invertedAceEth.getDestinationMacAddress(), aceEth.getSourceMacAddress());
    assertEquals(invertedAceEth.getSourceMacAddress(), aceEth.getDestinationMacAddress());
}
Also used : AceEthBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceEthBuilder) Matches(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches) AceEth(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceEth) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) MatchesBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder) Test(org.junit.Test)

Example 10 with MatchesBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder in project netvirt by opendaylight.

the class AclServiceTestBase method newMatch.

// TODO refactor this instead of stealing it from org.opendaylight.netvirt.neutronvpn.NeutronSecurityRuleListener
protected Matches newMatch(int srcLowerPort, int srcUpperPort, int destLowerPort, int destupperPort, int srcRemoteIpPrefix, int dstRemoteIpPrefix, short protocol) {
    AceIpBuilder aceIpBuilder = new AceIpBuilder();
    if (destLowerPort != -1) {
        DestinationPortRangeBuilder destinationPortRangeBuilder = new DestinationPortRangeBuilder();
        destinationPortRangeBuilder.setLowerPort(new PortNumber(destLowerPort));
        destinationPortRangeBuilder.setUpperPort(new PortNumber(destupperPort));
        aceIpBuilder.setDestinationPortRange(destinationPortRangeBuilder.build());
    }
    AceIpv4Builder aceIpv4Builder = new AceIpv4Builder();
    if (srcRemoteIpPrefix == AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED) {
        aceIpv4Builder.setSourceIpv4Network(new Ipv4Prefix(AclConstants.IPV4_ALL_NETWORK));
    }
    if (dstRemoteIpPrefix == AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED) {
        aceIpv4Builder.setSourceIpv4Network(new Ipv4Prefix(AclConstants.IPV4_ALL_NETWORK));
    }
    if (protocol != -1) {
        aceIpBuilder.setProtocol(protocol);
    }
    aceIpBuilder.setAceIpVersion(aceIpv4Builder.build());
    MatchesBuilder matchesBuilder = new MatchesBuilder();
    matchesBuilder.setAceType(aceIpBuilder.build());
    return matchesBuilder.build();
}
Also used : DestinationPortRangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRangeBuilder) AceIpBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) AceIpv4Builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4Builder) MatchesBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)

Aggregations

MatchesBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder)18 AceIpBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder)13 Test (org.junit.Test)12 DestinationPortRangeBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRangeBuilder)9 AceIpv4Builder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4Builder)8 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)8 Matches (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches)7 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)7 EthernetMatch (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch)6 AceIpv6Builder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv6Builder)5 SourcePortRangeBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.SourcePortRangeBuilder)5 AceEthBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceEthBuilder)4 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)4 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)4 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)4 AceIp (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIp)3 Dscp (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp)3 DestinationPortRange (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRange)3 SourcePortRange (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.SourcePortRange)3 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)3