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.matches.ace.type.AceEthBuilder in project netvirt by opendaylight.
the class AclMatches method invertMatches.
public static Matches invertMatches(Matches matches) {
LOG.trace("Invert matches: {}", matches);
MatchesBuilder matchesBuilder = new MatchesBuilder(matches);
if (matches.getAceType() instanceof AceIp) {
AceIp aceIp = (AceIp) matches.getAceType();
AceIpBuilder aceIpBuilder = new AceIpBuilder(aceIp);
aceIpBuilder.setDestinationPortRange(null);
aceIpBuilder.setSourcePortRange(null);
SourcePortRange sourcePortRange = aceIp.getSourcePortRange();
DestinationPortRange destinationPortRange = aceIp.getDestinationPortRange();
if (sourcePortRange != null) {
DestinationPortRangeBuilder destinationPortRangeBuilder = new DestinationPortRangeBuilder();
destinationPortRangeBuilder.setLowerPort(sourcePortRange.getLowerPort());
destinationPortRangeBuilder.setUpperPort(sourcePortRange.getUpperPort());
aceIpBuilder.setDestinationPortRange(destinationPortRangeBuilder.build());
}
if (destinationPortRange != null) {
SourcePortRangeBuilder sourcePortRangeBuilder = new SourcePortRangeBuilder();
sourcePortRangeBuilder.setLowerPort(destinationPortRange.getLowerPort());
sourcePortRangeBuilder.setUpperPort(destinationPortRange.getUpperPort());
aceIpBuilder.setSourcePortRange(sourcePortRangeBuilder.build());
}
if (aceIp.getAceIpVersion() instanceof AceIpv4) {
AceIpv4 aceIpv4 = (AceIpv4) aceIp.getAceIpVersion();
Ipv4Prefix destinationIpv4Network = aceIpv4.getDestinationIpv4Network();
Ipv4Prefix sourceIpv4Network = aceIpv4.getSourceIpv4Network();
AceIpv4Builder aceIpv4Builder = new AceIpv4Builder(aceIpv4);
aceIpv4Builder.setDestinationIpv4Network(sourceIpv4Network);
aceIpv4Builder.setSourceIpv4Network(destinationIpv4Network);
aceIpBuilder.setAceIpVersion(aceIpv4Builder.build());
} else if (aceIp.getAceIpVersion() instanceof AceIpv6) {
AceIpv6 aceIpv6 = (AceIpv6) aceIp.getAceIpVersion();
Ipv6Prefix destinationIpv6Network = aceIpv6.getDestinationIpv6Network();
Ipv6Prefix sourceIpv6Network = aceIpv6.getSourceIpv6Network();
AceIpv6Builder aceIpv6Builder = new AceIpv6Builder(aceIpv6);
aceIpv6Builder.setDestinationIpv6Network(sourceIpv6Network);
aceIpv6Builder.setSourceIpv6Network(destinationIpv6Network);
aceIpBuilder.setAceIpVersion(aceIpv6Builder.build());
}
matchesBuilder.setAceType(aceIpBuilder.build());
} else if (matches.getAceType() instanceof AceEth) {
AceEth aceEth = (AceEth) matches.getAceType();
MacAddress destinationMacAddress = aceEth.getDestinationMacAddress();
MacAddress destinationMacAddressMask = aceEth.getDestinationMacAddressMask();
MacAddress sourceMacAddress = aceEth.getSourceMacAddress();
MacAddress sourceMacAddressMask = aceEth.getSourceMacAddressMask();
AceEthBuilder aceEthBuilder = new AceEthBuilder(aceEth);
aceEthBuilder.setDestinationMacAddress(sourceMacAddress);
aceEthBuilder.setDestinationMacAddressMask(sourceMacAddressMask);
aceEthBuilder.setSourceMacAddress(destinationMacAddress);
aceEthBuilder.setSourceMacAddressMask(destinationMacAddressMask);
matchesBuilder.setAceType(aceEthBuilder.build());
}
Matches invertedMatches = matchesBuilder.build();
LOG.trace("Inverted matches: {}", invertedMatches);
return invertedMatches;
}
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.matches.ace.type.AceEthBuilder in project netvirt by opendaylight.
the class ClassifierEntryTest method buildMatchEntry.
private ClassifierEntry buildMatchEntry() {
AceType aceType = new AceEthBuilder().setDestinationMacAddress(new MacAddress("12:34:56:78:90:AB")).build();
Matches matches = new MatchesBuilder().setAceType(aceType).build();
return ClassifierEntry.buildMatchEntry(new NodeId("node"), "connector", matches, 100L, (short) 254);
}
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.matches.ace.type.AceEthBuilder 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());
}
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.matches.ace.type.AceEthBuilder 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());
}
Aggregations