use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder in project openflowplugin by opendaylight.
the class EthernetSourceEntrySerializerTest method testSerialize.
@Test
public void testSerialize() throws Exception {
final MacAddress address = new MacAddress("00:01:02:03:04:05");
final MacAddress mask = new MacAddress("00:00:00:00:00:00");
final Match match = new MatchBuilder().setEthernetMatch(new EthernetMatchBuilder().setEthernetSource(new EthernetSourceBuilder().setAddress(address).setMask(mask).build()).build()).build();
assertMatch(match, true, (out) -> {
final byte[] addressBytes = new byte[6];
out.readBytes(addressBytes);
assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
final byte[] maskBytes = new byte[6];
out.readBytes(maskBytes);
assertEquals(new MacAddress(ByteBufUtils.macAddressToString(maskBytes)).getValue(), mask.getValue());
});
final Match matchNoMask = new MatchBuilder().setEthernetMatch(new EthernetMatchBuilder().setEthernetSource(new EthernetSourceBuilder().setAddress(address).build()).build()).build();
assertMatch(matchNoMask, false, (out) -> {
final byte[] addressBytes = new byte[6];
out.readBytes(addressBytes);
assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder in project openflowplugin by opendaylight.
the class BulkOMaticUtils method getMatch.
public static Match getMatch(final int sourceIp) {
Ipv4Match ipv4Match = new Ipv4MatchBuilder().setIpv4Source(new Ipv4Prefix(ipIntToStr(sourceIp))).build();
MatchBuilder matchBuilder = new MatchBuilder();
matchBuilder.setLayer3Match(ipv4Match);
EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
ethTypeBuilder.setType(new EtherType(2048L));
ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
return matchBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder in project openflowplugin by opendaylight.
the class FlowCreatorUtilTest method createMatch.
/**
* Create a flow match that specifies ethernet type.
*
* @param etherType An ethernet type value.
* @return A flow match that specifies the given ethernet type.
*/
private static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match createMatch(final long etherType) {
final EthernetTypeBuilder ethType = new EthernetTypeBuilder().setType(new EtherType(etherType));
final EthernetMatchBuilder ether = new EthernetMatchBuilder().setEthernetType(ethType.build());
return new MatchBuilder().setEthernetMatch(ether.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder in project openflowplugin by opendaylight.
the class OFPluginFlowTest method createMatch1.
private static MatchBuilder createMatch1() {
MatchBuilder match = new MatchBuilder();
Ipv4MatchBuilder ipv4Match = new Ipv4MatchBuilder();
Ipv4Prefix prefix = new Ipv4Prefix("10.0.0.1/24");
ipv4Match.setIpv4Destination(prefix);
Ipv4Match i4m = ipv4Match.build();
match.setLayer3Match(i4m);
EthernetMatchBuilder eth = new EthernetMatchBuilder();
EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
ethTypeBuilder.setType(new EtherType(0x0800L));
eth.setEthernetType(ethTypeBuilder.build());
match.setEthernetMatch(eth.build());
return match;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder in project openflowplugin by opendaylight.
the class MatchConvertorTest method testConversionWithMasks.
@Test
public void testConversionWithMasks() {
MatchBuilder builder = new MatchBuilder();
MetadataBuilder metadataBuilder = new MetadataBuilder();
metadataBuilder.setMetadata(new BigInteger("3"));
metadataBuilder.setMetadataMask(new BigInteger("15"));
builder.setMetadata(metadataBuilder.build());
EthernetMatchBuilder ethernetBuilder = new EthernetMatchBuilder();
EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
ethSrcBuilder.setAddress(new MacAddress("00:00:00:00:00:05"));
ethSrcBuilder.setMask(new MacAddress("00:00:00:00:00:08"));
ethernetBuilder.setEthernetSource(ethSrcBuilder.build());
EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
ethDstBuilder.setAddress(new MacAddress("00:00:00:00:00:06"));
ethDstBuilder.setMask(new MacAddress("00:00:00:00:00:09"));
ethernetBuilder.setEthernetDestination(ethDstBuilder.build());
builder.setEthernetMatch(ethernetBuilder.build());
VlanMatchBuilder vlanBuilder = new VlanMatchBuilder();
VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
vlanIdBuilder.setVlanId(new VlanId(0));
vlanIdBuilder.setVlanIdPresent(true);
vlanBuilder.setVlanId(vlanIdBuilder.build());
builder.setVlanMatch(vlanBuilder.build());
ProtocolMatchFieldsBuilder protoBuilder = new ProtocolMatchFieldsBuilder();
PbbBuilder pbbBuilder = new PbbBuilder();
pbbBuilder.setPbbIsid(20L);
pbbBuilder.setPbbMask(8L);
protoBuilder.setPbb(pbbBuilder.build());
builder.setProtocolMatchFields(protoBuilder.build());
TunnelBuilder tunnelBuilder = new TunnelBuilder();
tunnelBuilder.setTunnelId(new BigInteger("21"));
tunnelBuilder.setTunnelMask(new BigInteger("14"));
builder.setTunnel(tunnelBuilder.build());
Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix("10.0.0.0/24"));
ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix("10.0.0.0/8"));
builder.setLayer3Match(ipv4MatchBuilder.build());
Match match = builder.build();
Optional<List<MatchEntry>> entriesOptional = converterManager.convert(match, new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
List<MatchEntry> entries = entriesOptional.get();
Assert.assertEquals("Wrong entries size", 8, entries.size());
MatchEntry entry = entries.get(0);
checkEntryHeader(entry, Metadata.class, true);
Assert.assertArrayEquals("Wrong metadata", new byte[] { 0, 0, 0, 0, 0, 0, 0, 3 }, ((MetadataCase) entry.getMatchEntryValue()).getMetadata().getMetadata());
Assert.assertArrayEquals("Wrong metadata mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 15 }, ((MetadataCase) entry.getMatchEntryValue()).getMetadata().getMask());
entry = entries.get(1);
checkEntryHeader(entry, EthDst.class, true);
Assert.assertEquals("Wrong eth dst", new MacAddress("00:00:00:00:00:06"), ((EthDstCase) entry.getMatchEntryValue()).getEthDst().getMacAddress());
Assert.assertArrayEquals("Wrong eth dst mask", new byte[] { 0, 0, 0, 0, 0, 9 }, ((EthDstCase) entry.getMatchEntryValue()).getEthDst().getMask());
entry = entries.get(2);
checkEntryHeader(entry, EthSrc.class, true);
Assert.assertEquals("Wrong eth src", new MacAddress("00:00:00:00:00:05"), ((EthSrcCase) entry.getMatchEntryValue()).getEthSrc().getMacAddress());
Assert.assertArrayEquals("Wrong eth src mask", new byte[] { 0, 0, 0, 0, 0, 8 }, ((EthSrcCase) entry.getMatchEntryValue()).getEthSrc().getMask());
entry = entries.get(3);
checkEntryHeader(entry, VlanVid.class, true);
Assert.assertEquals("Wrong vlan id", 0, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().getVlanVid().intValue());
Assert.assertEquals("Wrong cfi bit", true, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().isCfiBit());
Assert.assertArrayEquals("Wrong vlanId mask", new byte[] { 16, 0 }, ((VlanVidCase) entry.getMatchEntryValue()).getVlanVid().getMask());
entry = entries.get(4);
checkEntryHeader(entry, Ipv4Src.class, true);
Assert.assertEquals("Wrong ipv4 src", "10.0.0.0", ((Ipv4SrcCase) entry.getMatchEntryValue()).getIpv4Src().getIpv4Address().getValue());
Assert.assertArrayEquals("Wrong ipv4 src mask", new byte[] { (byte) 255, (byte) 255, (byte) 255, 0 }, ((Ipv4SrcCase) entry.getMatchEntryValue()).getIpv4Src().getMask());
entry = entries.get(5);
checkEntryHeader(entry, Ipv4Dst.class, true);
Assert.assertEquals("Wrong ipv4 dst", "10.0.0.0", ((Ipv4DstCase) entry.getMatchEntryValue()).getIpv4Dst().getIpv4Address().getValue());
Assert.assertArrayEquals("Wrong ipv4 dst mask", new byte[] { (byte) 255, 0, 0, 0 }, ((Ipv4DstCase) entry.getMatchEntryValue()).getIpv4Dst().getMask());
entry = entries.get(6);
checkEntryHeader(entry, PbbIsid.class, true);
Assert.assertEquals("Wrong pbb isid", 20, ((PbbIsidCase) entry.getMatchEntryValue()).getPbbIsid().getIsid().intValue());
Assert.assertArrayEquals("Wrong pbb isid mask", new byte[] { 0, 0, 8 }, ((PbbIsidCase) entry.getMatchEntryValue()).getPbbIsid().getMask());
entry = entries.get(7);
checkEntryHeader(entry, TunnelId.class, true);
Assert.assertArrayEquals("Wrong tunnel id", new byte[] { 0, 0, 0, 0, 0, 0, 0, 21 }, ((TunnelIdCase) entry.getMatchEntryValue()).getTunnelId().getTunnelId());
Assert.assertArrayEquals("Wrong tunnel id mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 14 }, ((TunnelIdCase) entry.getMatchEntryValue()).getTunnelId().getMask());
}
Aggregations