use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags in project openflowplugin by opendaylight.
the class MatchConvertorTest method testIpv6MatchConversion.
@Test
public void testIpv6MatchConversion() {
Ipv6MatchBuilder ipv6Builder = new Ipv6MatchBuilder();
ipv6Builder.setIpv6Source(new Ipv6Prefix("::1/128"));
ipv6Builder.setIpv6Destination(new Ipv6Prefix("::2/128"));
Ipv6LabelBuilder ipv6LabelBuilder = new Ipv6LabelBuilder();
ipv6LabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(3L));
ipv6Builder.setIpv6Label(ipv6LabelBuilder.build());
ipv6Builder.setIpv6NdTarget(new Ipv6Address("::4"));
ipv6Builder.setIpv6NdSll(new MacAddress("00:00:00:00:00:05"));
ipv6Builder.setIpv6NdTll(new MacAddress("00:00:00:00:00:06"));
Ipv6ExtHeaderBuilder extHdrBuilder = new Ipv6ExtHeaderBuilder();
extHdrBuilder.setIpv6Exthdr(153);
ipv6Builder.setIpv6ExtHeader(extHdrBuilder.build());
MatchBuilder builder = new MatchBuilder();
builder.setLayer3Match(ipv6Builder.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", 7, entries.size());
MatchEntry entry = entries.get(0);
/* Due to conversion ambiguities, we always get "has mask" because
* an ip with no mask and prefix with /128 (or 32 in v4) cannot
* be distinguished */
checkEntryHeader(entry, Ipv6Src.class, true);
Assert.assertEquals("Wrong ipv6 src", "::1", ((Ipv6SrcCase) entry.getMatchEntryValue()).getIpv6Src().getIpv6Address().getValue());
entry = entries.get(1);
checkEntryHeader(entry, Ipv6Dst.class, true);
Assert.assertEquals("Wrong ipv6 dst", "::2", ((Ipv6DstCase) entry.getMatchEntryValue()).getIpv6Dst().getIpv6Address().getValue());
entry = entries.get(2);
checkEntryHeader(entry, Ipv6Flabel.class, false);
Assert.assertEquals("Wrong ipv6 flabel", 3, ((Ipv6FlabelCase) entry.getMatchEntryValue()).getIpv6Flabel().getIpv6Flabel().getValue().intValue());
entry = entries.get(3);
checkEntryHeader(entry, Ipv6NdTarget.class, false);
Assert.assertEquals("Wrong ipv6 nd target", "::4", ((Ipv6NdTargetCase) entry.getMatchEntryValue()).getIpv6NdTarget().getIpv6Address().getValue());
entry = entries.get(4);
checkEntryHeader(entry, Ipv6NdSll.class, false);
Assert.assertEquals("Wrong ipv6 nd sll", "00:00:00:00:00:05", ((Ipv6NdSllCase) entry.getMatchEntryValue()).getIpv6NdSll().getMacAddress().getValue());
entry = entries.get(5);
checkEntryHeader(entry, Ipv6NdTll.class, false);
Assert.assertEquals("Wrong ipv6 nd tll", "00:00:00:00:00:06", ((Ipv6NdTllCase) entry.getMatchEntryValue()).getIpv6NdTll().getMacAddress().getValue());
entry = entries.get(6);
checkEntryHeader(entry, Ipv6Exthdr.class, false);
Assert.assertEquals("Wrong ipv6 ext hdr", new Ipv6ExthdrFlags(false, true, false, true, false, true, false, true, false), ((Ipv6ExthdrCase) entry.getMatchEntryValue()).getIpv6Exthdr().getPseudoField());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags in project openflowplugin by opendaylight.
the class OfToSalIpv6ExthdrCase method process.
@Override
public Optional<MatchBuilder> process(@Nonnull Ipv6ExthdrCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) {
final MatchBuilder matchBuilder = data.getMatchBuilder();
final Ipv6MatchBuilder ipv6MatchBuilder = data.getIpv6MatchBuilder();
Ipv6Exthdr ipv6Exthdr = source.getIpv6Exthdr();
if (ipv6Exthdr != null) {
Ipv6ExtHeaderBuilder ipv6ExtHeaderBuilder = new Ipv6ExtHeaderBuilder();
Ipv6ExthdrFlags headerFlags = ipv6Exthdr.getPseudoField();
Integer bitmap = MatchConvertorUtil.ipv6ExthdrFlagsToInt(headerFlags);
ipv6ExtHeaderBuilder.setIpv6Exthdr(bitmap);
byte[] mask = ipv6Exthdr.getMask();
if (mask != null) {
ipv6ExtHeaderBuilder.setIpv6ExthdrMask(ByteUtil.bytesToUnsignedShort(mask));
}
ipv6MatchBuilder.setIpv6ExtHeader(ipv6ExtHeaderBuilder.build());
matchBuilder.setLayer3Match(ipv6MatchBuilder.build());
}
return Optional.of(matchBuilder);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags in project openflowplugin by opendaylight.
the class OxmIpv6ExtHdrSerializer method serialize.
@Override
public void serialize(MatchEntry entry, ByteBuf outBuffer) {
super.serialize(entry, outBuffer);
Ipv6ExthdrCase entryValue = (Ipv6ExthdrCase) entry.getMatchEntryValue();
Ipv6ExthdrFlags pseudoField = entryValue.getIpv6Exthdr().getPseudoField();
int bitmap = ByteBufUtils.fillBitMask(0, pseudoField.isNonext(), pseudoField.isEsp(), pseudoField.isAuth(), pseudoField.isDest(), pseudoField.isFrag(), pseudoField.isRouter(), pseudoField.isHop(), pseudoField.isUnrep(), pseudoField.isUnseq());
outBuffer.writeShort(bitmap);
if (entry.isHasMask()) {
outBuffer.writeBytes(entryValue.getIpv6Exthdr().getMask());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags in project openflowplugin by opendaylight.
the class OxmIpv6ExtHdrSerializerTest method prepareIpv6ExtHdrMatchEntry.
private static MatchEntryBuilder prepareIpv6ExtHdrMatchEntry(boolean hasMask, Ipv6ExthdrFlags flags) {
final MatchEntryBuilder builder = prepareIpv6ExtHdrHeader(hasMask);
Ipv6ExthdrCaseBuilder casebuilder = new Ipv6ExthdrCaseBuilder();
Ipv6ExthdrBuilder valueBuilder = new Ipv6ExthdrBuilder();
if (hasMask) {
valueBuilder.setMask(new byte[] { 0, 15 });
}
valueBuilder.setPseudoField(flags);
casebuilder.setIpv6Exthdr(valueBuilder.build());
builder.setMatchEntryValue(casebuilder.build());
return builder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags in project openflowplugin by opendaylight.
the class OxmIpv6ExtHdrSerializerTest method testSerializeWithMask.
/**
* Test correct serialization.
*/
@Test
public void testSerializeWithMask() {
MatchEntryBuilder builder = prepareIpv6ExtHdrMatchEntry(true, new Ipv6ExthdrFlags(false, true, false, true, false, true, false, true, false));
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
serializer.serialize(builder.build(), buffer);
checkHeader(buffer, true);
assertEquals("Wrong value", 153, buffer.readUnsignedShort());
byte[] tmp = new byte[2];
buffer.readBytes(tmp);
Assert.assertArrayEquals("Wrong mask", new byte[] { 0, 15 }, tmp);
assertTrue("Unexpected data", buffer.readableBytes() == 0);
}
Aggregations