use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch in project netvirt by opendaylight.
the class AclMatchesTest method buildIpv4UdpMatchTest.
@Test
public void buildIpv4UdpMatchTest() {
AceIpBuilder aceIpBuilder = new AceIpBuilder();
aceIpBuilder.setAceIpVersion(new AceIpv4Builder().build());
aceIpBuilder.setProtocol(IPProtocols.UDP.shortValue());
SourcePortRangeBuilder srcPortRange = new SourcePortRangeBuilder();
srcPortRange.setLowerPort(new PortNumber(UDP_SRC_LOWER_PORT));
srcPortRange.setUpperPort(new PortNumber(UDP_SRC_UPPER_PORT));
aceIpBuilder.setSourcePortRange(srcPortRange.build());
DestinationPortRangeBuilder dstPortRange = new DestinationPortRangeBuilder();
dstPortRange.setLowerPort(new PortNumber(UDP_DST_LOWER_PORT));
dstPortRange.setUpperPort(new PortNumber(UDP_DST_UPPER_PORT));
aceIpBuilder.setDestinationPortRange(dstPortRange.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();
// There should be an IPv4 etherType set
EthernetMatch ethMatch = matchBuilder.getEthernetMatch();
assertNotNull(ethMatch);
assertEquals(ethMatch.getEthernetType().getType().getValue(), Long.valueOf(NwConstants.ETHTYPE_IPV4));
// Make sure its UDP
IpMatch ipMatch = matchBuilder.getIpMatch();
assertNotNull(ipMatch);
assertEquals(ipMatch.getIpProtocol(), Short.valueOf(IPProtocols.UDP.shortValue()));
// Currently ranges arent supported, only the lower port is used
UdpMatch udpMatch = (UdpMatch) matchBuilder.getLayer4Match();
assertEquals(udpMatch.getUdpSourcePort().getValue(), Integer.valueOf(UDP_SRC_LOWER_PORT));
assertEquals(udpMatch.getUdpDestinationPort().getValue(), Integer.valueOf(UDP_DST_LOWER_PORT));
// The layer3 match should be null
assertNull(matchBuilder.getLayer3Match());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch in project netvirt by opendaylight.
the class AclMatchesTest method buildIpv4TcpMatchTest.
@Test
public void buildIpv4TcpMatchTest() {
AceIpBuilder aceIpBuilder = new AceIpBuilder();
aceIpBuilder.setAceIpVersion(new AceIpv4Builder().build());
aceIpBuilder.setProtocol(IPProtocols.TCP.shortValue());
SourcePortRangeBuilder srcPortRange = new SourcePortRangeBuilder();
srcPortRange.setLowerPort(new PortNumber(TCP_SRC_LOWER_PORT));
srcPortRange.setUpperPort(new PortNumber(TCP_SRC_UPPER_PORT));
aceIpBuilder.setSourcePortRange(srcPortRange.build());
DestinationPortRangeBuilder dstPortRange = new DestinationPortRangeBuilder();
dstPortRange.setLowerPort(new PortNumber(TCP_DST_LOWER_PORT));
dstPortRange.setUpperPort(new PortNumber(TCP_DST_UPPER_PORT));
aceIpBuilder.setDestinationPortRange(dstPortRange.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();
// There should be an IPv4 etherType set
EthernetMatch ethMatch = matchBuilder.getEthernetMatch();
assertNotNull(ethMatch);
assertEquals(ethMatch.getEthernetType().getType().getValue(), Long.valueOf(NwConstants.ETHTYPE_IPV4));
// Make sure its TCP
IpMatch ipMatch = matchBuilder.getIpMatch();
assertNotNull(ipMatch);
assertEquals(ipMatch.getIpProtocol(), Short.valueOf(IPProtocols.TCP.shortValue()));
// Currently ranges arent supported, only the lower port is used
TcpMatch tcpMatch = (TcpMatch) matchBuilder.getLayer4Match();
assertEquals(tcpMatch.getTcpSourcePort().getValue(), Integer.valueOf(TCP_SRC_LOWER_PORT));
assertEquals(tcpMatch.getTcpDestinationPort().getValue(), Integer.valueOf(TCP_DST_LOWER_PORT));
// The layer3 match should be null
assertNull(matchBuilder.getLayer3Match());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch in project openflowplugin by opendaylight.
the class MatchResponseConvertorTest method checkDefaultV10.
private static void checkDefaultV10(final Match match, final FlowWildcardsV10 wc, final int vid) {
EthernetMatch ethMatch = match.getEthernetMatch();
if (wc.isDLSRC()) {
if (ethMatch != null) {
assertEquals(null, ethMatch.getEthernetSource());
}
} else {
assertEquals(MAC_SRC, ethMatch.getEthernetSource().getAddress());
}
if (ethMatch != null) {
if (wc.isDLDST()) {
assertEquals(null, ethMatch.getEthernetDestination());
} else {
assertNotEquals(null, ethMatch.getEthernetDestination());
assertEquals(MAC_DST, ethMatch.getEthernetDestination().getAddress());
}
}
if (wc.isDLTYPE()) {
if (ethMatch != null) {
assertEquals(null, ethMatch.getEthernetType());
}
assertEquals(null, match.getLayer3Match());
} else {
assert ethMatch != null;
assertEquals(ETHTYPE_IPV4, ethMatch.getEthernetType().getType().getValue().intValue());
Ipv4Match ipv4Match = (Ipv4Match) match.getLayer3Match();
assertEquals(IPV4_SRC.getValue() + "/32", ipv4Match.getIpv4Source().getValue());
assertEquals(IPV4_DST.getValue() + "/32", ipv4Match.getIpv4Destination().getValue());
}
VlanMatch vlanMatch = match.getVlanMatch();
if (wc.isDLVLAN()) {
assertEquals(null, vlanMatch);
} else {
int expectedVid;
Boolean expectedCfi;
if (vid == DL_VLAN_NONE) {
expectedVid = 0;
expectedCfi = Boolean.FALSE;
} else {
expectedVid = vid;
expectedCfi = Boolean.TRUE;
}
assertEquals(expectedVid, vlanMatch.getVlanId().getVlanId().getValue().intValue());
assertEquals(expectedCfi, vlanMatch.getVlanId().isVlanIdPresent());
if (wc.isDLVLANPCP()) {
assertEquals(null, vlanMatch.getVlanPcp());
} else {
assertEquals(VLAN_PCP, vlanMatch.getVlanPcp().getValue().shortValue());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch in project openflowplugin by opendaylight.
the class AbstractDropTest method processPacket.
@SuppressWarnings("checkstyle:IllegalCatch")
private void processPacket(final PacketReceived notification) {
try {
final byte[] rawPacket = notification.getPayload();
final byte[] srcMac = Arrays.copyOfRange(rawPacket, 6, 12);
final MatchBuilder match = new MatchBuilder();
final EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
final EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
// TODO: use HEX, use binary form
// Hex.decodeHex("000000000001".toCharArray());
ethSourceBuilder.setAddress(new MacAddress(macAddressToString(srcMac)));
ethernetMatch.setEthernetSource(ethSourceBuilder.build());
match.setEthernetMatch(ethernetMatch.build());
// Get the Ingress nodeConnectorRef
final NodeConnectorRef ncr = notification.getIngress();
// Get the instance identifier for the nodeConnectorRef
final InstanceIdentifier<?> ncri = ncr.getValue();
processPacket(ncri.firstIdentifierOf(Node.class), match.build(), DROP_INSTRUCTIONS);
SENT_UPDATER.incrementAndGet(this);
} catch (RuntimeException e) {
LOG.warn("Failed to process packet: {}", e.getMessage());
LOG.debug("Failed to process packet.. ", e);
EXCS_UPDATER.incrementAndGet(this);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch in project openflowplugin by opendaylight.
the class OpenflowPluginBulkGroupTransactionProvider method createMatch3.
private static MatchBuilder createMatch3() {
MatchBuilder match = new MatchBuilder();
EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
ethSourceBuilder.setAddress(new MacAddress("00:00:00:00:00:01"));
ethernetMatch.setEthernetSource(ethSourceBuilder.build());
match.setEthernetMatch(ethernetMatch.build());
return match;
}
Aggregations