use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch in project openflowplugin by opendaylight.
the class OpenflowpluginTestCommandProvider method createAppyActionInstruction43.
private static InstructionsBuilder createAppyActionInstruction43() {
final List<Action> actionList = new ArrayList<>();
final ActionBuilder ab = new ActionBuilder();
final ActionBuilder ab1 = new ActionBuilder();
final ActionBuilder ab2 = new ActionBuilder();
final ActionBuilder ab3 = new ActionBuilder();
final ActionBuilder ab4 = new ActionBuilder();
final SetFieldBuilder setFieldBuilder = new SetFieldBuilder();
final SetFieldBuilder setFieldBuilder1 = new SetFieldBuilder();
final SetFieldBuilder setFieldBuilder2 = new SetFieldBuilder();
final SetFieldBuilder setFieldBuilder3 = new SetFieldBuilder();
final SetFieldBuilder setFieldBuilder4 = new SetFieldBuilder();
// setting the values of ARP
final MacAddress macdest = new MacAddress(DEST_MAC_ADDRESS);
final MacAddress macsrc = new MacAddress(SRC_MAC_ADDRESS);
final Ipv4Prefix dstiparp = new Ipv4Prefix("200.71.9.52");
final Ipv4Prefix srciparp = new Ipv4Prefix("100.1.1.1");
// create ARP match action
final ArpMatchBuilder arpmatch = new ArpMatchBuilder();
final ArpMatchBuilder arpmatch1 = new ArpMatchBuilder();
final ArpMatchBuilder arpmatch2 = new ArpMatchBuilder();
final ArpMatchBuilder arpmatch3 = new ArpMatchBuilder();
final ArpMatchBuilder arpmatch4 = new ArpMatchBuilder();
final ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
arpsrc.setAddress(macsrc);
final ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
arpdst.setAddress(macdest);
arpmatch.setArpOp(2);
arpmatch1.setArpSourceHardwareAddress(arpsrc.build());
arpmatch2.setArpTargetHardwareAddress(arpdst.build());
arpmatch3.setArpSourceTransportAddress(srciparp);
arpmatch4.setArpTargetTransportAddress(dstiparp);
setFieldBuilder.setLayer3Match(arpmatch.build());
ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build());
ab.setKey(new ActionKey(0));
actionList.add(ab.build());
setFieldBuilder1.setLayer3Match(arpmatch1.build());
ab1.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder1.build()).build());
ab1.setKey(new ActionKey(1));
actionList.add(ab1.build());
setFieldBuilder2.setLayer3Match(arpmatch2.build());
ab2.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder2.build()).build());
ab2.setKey(new ActionKey(2));
actionList.add(ab2.build());
setFieldBuilder3.setLayer3Match(arpmatch3.build());
ab3.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder3.build()).build());
ab3.setKey(new ActionKey(3));
actionList.add(ab3.build());
setFieldBuilder4.setLayer3Match(arpmatch4.build());
ab4.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder4.build()).build());
ab4.setKey(new ActionKey(4));
actionList.add(ab4.build());
final ApplyActionsBuilder aab = new ApplyActionsBuilder();
aab.setAction(actionList);
final InstructionBuilder ib = new InstructionBuilder();
ib.setKey(new InstructionKey(0));
ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build());
// Put our Instruction in a list of Instructions
final InstructionsBuilder isb = new InstructionsBuilder();
final List<Instruction> instructions = new ArrayList<>();
instructions.add(ib.build());
isb.setInstruction(instructions);
return isb;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch in project openflowplugin by opendaylight.
the class MatchResponseConvertor2Test method testLayer3MatchArpWithMasks.
/**
* Test {@link MatchResponseConvertor#convert(MatchEntriesGrouping, VersionDatapathIdConvertorData)}.
*/
@Test
public void testLayer3MatchArpWithMasks() {
final MatchBuilder builder = new MatchBuilder();
builder.setType(OxmMatchType.class);
final List<MatchEntry> entries = new ArrayList<>();
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(ArpSpa.class);
entriesBuilder.setHasMask(true);
final ArpSpaCaseBuilder arpSpaCaseBuilder = new ArpSpaCaseBuilder();
final ArpSpaBuilder arpSpaBuilder = new ArpSpaBuilder();
arpSpaBuilder.setIpv4Address(new Ipv4Address("10.0.0.3"));
arpSpaBuilder.setMask(new byte[] { (byte) 255, (byte) 255, (byte) 255, 0 });
arpSpaCaseBuilder.setArpSpa(arpSpaBuilder.build());
entriesBuilder.setMatchEntryValue(arpSpaCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(ArpTpa.class);
entriesBuilder.setHasMask(true);
final ArpTpaCaseBuilder arpTpaCaseBuilder = new ArpTpaCaseBuilder();
final ArpTpaBuilder arpTpaBuilder = new ArpTpaBuilder();
arpTpaBuilder.setIpv4Address(new Ipv4Address("10.0.0.0"));
arpTpaBuilder.setMask(new byte[] { (byte) 255, (byte) 128, 0, 0 });
arpTpaCaseBuilder.setArpTpa(arpTpaBuilder.build());
entriesBuilder.setMatchEntryValue(arpTpaCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(ArpSha.class);
entriesBuilder.setHasMask(true);
final ArpShaCaseBuilder arpShaCaseBuilder = new ArpShaCaseBuilder();
final ArpShaBuilder arpShaBuilder = new ArpShaBuilder();
arpShaBuilder.setMacAddress(new MacAddress("00:00:00:00:00:03"));
arpShaBuilder.setMask(new byte[] { 0, 0, 1, 0, 4, 0 });
arpShaCaseBuilder.setArpSha(arpShaBuilder.build());
entriesBuilder.setMatchEntryValue(arpShaCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpTha.class);
entriesBuilder.setHasMask(true);
final ArpThaCaseBuilder arpThaCaseBuilder = new ArpThaCaseBuilder();
final ArpThaBuilder arpThaBuilder = new ArpThaBuilder();
arpThaBuilder.setMacAddress(new MacAddress("00:00:00:00:00:04"));
arpThaBuilder.setMask(new byte[] { 1, 1, 1, 2, 2, 2 });
arpThaCaseBuilder.setArpTha(arpThaBuilder.build());
entriesBuilder.setMatchEntryValue(arpThaCaseBuilder.build());
entries.add(entriesBuilder.build());
builder.setMatchEntry(entries);
final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
datapathIdConvertorData.setDatapathId(new BigInteger("42"));
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder salMatchBuilder = convert(builder.build(), datapathIdConvertorData);
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match builtMatch = salMatchBuilder.build();
final ArpMatch arpMatch = (ArpMatch) builtMatch.getLayer3Match();
Assert.assertEquals("Wrong arp spa", "10.0.0.3/24", arpMatch.getArpSourceTransportAddress().getValue());
Assert.assertEquals("Wrong arp tpa", "10.0.0.0/9", arpMatch.getArpTargetTransportAddress().getValue());
Assert.assertEquals("Wrong arp sha", "00:00:00:00:00:03", arpMatch.getArpSourceHardwareAddress().getAddress().getValue());
Assert.assertEquals("Wrong arp sha mask", "00:00:01:00:04:00", arpMatch.getArpSourceHardwareAddress().getMask().getValue());
Assert.assertEquals("Wrong arp tha", "00:00:00:00:00:04", arpMatch.getArpTargetHardwareAddress().getAddress().getValue());
Assert.assertEquals("Wrong arp tha mask", "01:01:01:02:02:02", arpMatch.getArpTargetHardwareAddress().getMask().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch in project openflowplugin by opendaylight.
the class OpenflowpluginTestCommandProvider method createArpMatch.
private static MatchBuilder createArpMatch() {
final MatchBuilder match = new MatchBuilder();
final EthernetMatchBuilder ethmatch = new EthernetMatchBuilder();
final MacAddress macdest = new MacAddress(DEST_MAC_ADDRESS);
final MacAddress macsrc = new MacAddress(SRC_MAC_ADDRESS);
final EthernetTypeBuilder ethtype = new EthernetTypeBuilder();
final EtherType type = new EtherType(0x0806L);
ethmatch.setEthernetType(ethtype.setType(type).build());
// ipv4 match
final Ipv4Prefix dstip = new Ipv4Prefix("200.71.9.52/10");
final Ipv4Prefix srcip = new Ipv4Prefix("100.1.1.1/8");
// arp match
final ArpMatchBuilder arpmatch = new ArpMatchBuilder();
final ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder();
arpsrc.setAddress(macsrc);
arpsrc.setMask(new MacAddress("ff:ff:ff:00:00:00"));
final ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder();
arpdst.setAddress(macdest);
arpdst.setMask(new MacAddress("ff:ff:00:00:00:00"));
arpmatch.setArpOp(2);
arpmatch.setArpSourceHardwareAddress(arpsrc.build());
arpmatch.setArpTargetHardwareAddress(arpdst.build());
arpmatch.setArpSourceTransportAddress(srcip);
arpmatch.setArpTargetTransportAddress(dstip);
match.setEthernetMatch(ethmatch.build());
match.setLayer3Match(arpmatch.build());
return match;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch in project openflowplugin by opendaylight.
the class SalToOfArpMatchCase method process.
@Override
public Optional<List<MatchEntry>> process(@Nonnull ArpMatch source, VersionConvertorData data, ConvertorExecutor convertorExecutor) {
List<MatchEntry> result = new ArrayList<>();
if (source.getArpOp() != null) {
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntryBuilder.setHasMask(false);
matchEntryBuilder.setOxmMatchField(ArpOp.class);
ArpOpCaseBuilder arpOpCaseBuilder = new ArpOpCaseBuilder();
ArpOpBuilder arpOpBuilder = new ArpOpBuilder();
arpOpBuilder.setOpCode(source.getArpOp());
arpOpCaseBuilder.setArpOp(arpOpBuilder.build());
matchEntryBuilder.setMatchEntryValue(arpOpCaseBuilder.build());
result.add(matchEntryBuilder.build());
}
if (source.getArpSourceTransportAddress() != null) {
Ipv4Prefix ipv4Prefix = source.getArpSourceTransportAddress();
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntryBuilder.setOxmMatchField(ArpSpa.class);
ArpSpaBuilder arpSpaBuilder = new ArpSpaBuilder();
Iterator<String> addressParts = IpConversionUtil.splitToParts(ipv4Prefix);
Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
arpSpaBuilder.setIpv4Address(ipv4Address);
boolean hasMask = false;
byte[] mask = MatchConvertorUtil.extractIpv4Mask(addressParts);
if (null != mask) {
arpSpaBuilder.setMask(mask);
hasMask = true;
}
matchEntryBuilder.setHasMask(hasMask);
ArpSpaCaseBuilder arpSpaCaseBuilder = new ArpSpaCaseBuilder();
arpSpaCaseBuilder.setArpSpa(arpSpaBuilder.build());
matchEntryBuilder.setMatchEntryValue(arpSpaCaseBuilder.build());
result.add(matchEntryBuilder.build());
}
if (source.getArpTargetTransportAddress() != null) {
Ipv4Prefix ipv4Prefix = source.getArpTargetTransportAddress();
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntryBuilder.setOxmMatchField(ArpTpa.class);
ArpTpaBuilder arpTpaBuilder = new ArpTpaBuilder();
Iterator<String> addressParts = IpConversionUtil.splitToParts(ipv4Prefix);
Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
arpTpaBuilder.setIpv4Address(ipv4Address);
boolean hasMask = false;
byte[] mask = MatchConvertorUtil.extractIpv4Mask(addressParts);
if (null != mask) {
arpTpaBuilder.setMask(mask);
hasMask = true;
}
matchEntryBuilder.setHasMask(hasMask);
ArpTpaCaseBuilder arpTpaCaseBuilder = new ArpTpaCaseBuilder();
arpTpaCaseBuilder.setArpTpa(arpTpaBuilder.build());
matchEntryBuilder.setMatchEntryValue(arpTpaCaseBuilder.build());
result.add(matchEntryBuilder.build());
}
ArpSourceHardwareAddress arpSourceHardwareAddress = source.getArpSourceHardwareAddress();
if (arpSourceHardwareAddress != null) {
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntryBuilder.setOxmMatchField(ArpSha.class);
ArpShaCaseBuilder arpShaCaseBuilder = new ArpShaCaseBuilder();
ArpShaBuilder arpShaBuilder = new ArpShaBuilder();
arpShaBuilder.setMacAddress(arpSourceHardwareAddress.getAddress());
boolean hasMask = false;
if (null != arpSourceHardwareAddress.getMask()) {
arpShaBuilder.setMask(ByteBufUtils.macAddressToBytes(arpSourceHardwareAddress.getMask().getValue()));
hasMask = true;
}
arpShaCaseBuilder.setArpSha(arpShaBuilder.build());
matchEntryBuilder.setMatchEntryValue(arpShaCaseBuilder.build());
matchEntryBuilder.setHasMask(hasMask);
result.add(matchEntryBuilder.build());
}
ArpTargetHardwareAddress arpTargetHardwareAddress = source.getArpTargetHardwareAddress();
if (arpTargetHardwareAddress != null) {
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntryBuilder.setOxmMatchField(ArpTha.class);
ArpThaCaseBuilder arpThaCaseBuilder = new ArpThaCaseBuilder();
ArpThaBuilder arpThaBuilder = new ArpThaBuilder();
arpThaBuilder.setMacAddress(arpTargetHardwareAddress.getAddress());
boolean hasMask = false;
if (null != arpTargetHardwareAddress.getMask()) {
arpThaBuilder.setMask(ByteBufUtils.macAddressToBytes(arpTargetHardwareAddress.getMask().getValue()));
hasMask = true;
}
arpThaCaseBuilder.setArpTha(arpThaBuilder.build());
matchEntryBuilder.setMatchEntryValue(arpThaCaseBuilder.build());
matchEntryBuilder.setHasMask(hasMask);
result.add(matchEntryBuilder.build());
}
return Optional.of(result);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch in project openflowplugin by opendaylight.
the class MatchResponseConvertor2Test method testLayer3MatchArp.
/**
* Test {@link MatchResponseConvertor#convert(MatchEntriesGrouping, VersionDatapathIdConvertorData)}.
*/
@Test
public void testLayer3MatchArp() {
final MatchBuilder builder = new MatchBuilder();
builder.setType(OxmMatchType.class);
final List<MatchEntry> entries = new ArrayList<>();
MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(ArpOp.class);
entriesBuilder.setHasMask(false);
final ArpOpCaseBuilder arpOpCaseBuilder = new ArpOpCaseBuilder();
final ArpOpBuilder arpOpBuilder = new ArpOpBuilder();
arpOpBuilder.setOpCode(17);
arpOpCaseBuilder.setArpOp(arpOpBuilder.build());
entriesBuilder.setMatchEntryValue(arpOpCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(ArpSpa.class);
entriesBuilder.setHasMask(false);
final ArpSpaCaseBuilder arpSpaCaseBuilder = new ArpSpaCaseBuilder();
final ArpSpaBuilder arpSpaBuilder = new ArpSpaBuilder();
arpSpaBuilder.setIpv4Address(new Ipv4Address("10.0.0.3"));
arpSpaCaseBuilder.setArpSpa(arpSpaBuilder.build());
entriesBuilder.setMatchEntryValue(arpSpaCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(ArpTpa.class);
entriesBuilder.setHasMask(false);
final ArpTpaCaseBuilder arpTpaCaseBuilder = new ArpTpaCaseBuilder();
final ArpTpaBuilder arpTpaBuilder = new ArpTpaBuilder();
arpTpaBuilder.setIpv4Address(new Ipv4Address("10.0.0.4"));
arpTpaCaseBuilder.setArpTpa(arpTpaBuilder.build());
entriesBuilder.setMatchEntryValue(arpTpaCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(ArpSha.class);
entriesBuilder.setHasMask(false);
final ArpShaCaseBuilder arpShaCaseBuilder = new ArpShaCaseBuilder();
final ArpShaBuilder arpShaBuilder = new ArpShaBuilder();
arpShaBuilder.setMacAddress(new MacAddress("00:00:00:00:00:03"));
arpShaCaseBuilder.setArpSha(arpShaBuilder.build());
entriesBuilder.setMatchEntryValue(arpShaCaseBuilder.build());
entries.add(entriesBuilder.build());
entriesBuilder = new MatchEntryBuilder();
entriesBuilder.setOxmClass(OpenflowBasicClass.class);
entriesBuilder.setOxmMatchField(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.ArpTha.class);
entriesBuilder.setHasMask(false);
final ArpThaCaseBuilder arpThaCaseBuilder = new ArpThaCaseBuilder();
final ArpThaBuilder arpThaBuilder = new ArpThaBuilder();
arpThaBuilder.setMacAddress(new MacAddress("00:00:00:00:00:04"));
arpThaCaseBuilder.setArpTha(arpThaBuilder.build());
entriesBuilder.setMatchEntryValue(arpThaCaseBuilder.build());
entries.add(entriesBuilder.build());
builder.setMatchEntry(entries);
final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(OFConstants.OFP_VERSION_1_3);
datapathIdConvertorData.setDatapathId(new BigInteger("42"));
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder salMatchBuilder = convert(builder.build(), datapathIdConvertorData);
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match builtMatch = salMatchBuilder.build();
final ArpMatch arpMatch = (ArpMatch) builtMatch.getLayer3Match();
Assert.assertEquals("Wrong arp op", 17, arpMatch.getArpOp().intValue());
Assert.assertEquals("Wrong arp spa", "10.0.0.3/32", arpMatch.getArpSourceTransportAddress().getValue());
Assert.assertEquals("Wrong arp tpa", "10.0.0.4/32", arpMatch.getArpTargetTransportAddress().getValue());
Assert.assertEquals("Wrong arp sha", "00:00:00:00:00:03", arpMatch.getArpSourceHardwareAddress().getAddress().getValue());
Assert.assertEquals("Wrong arp tha", "00:00:00:00:00:04", arpMatch.getArpTargetHardwareAddress().getAddress().getValue());
}
Aggregations