use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatch in project openflowplugin by opendaylight.
the class TcpFlagsEntryDeserializer method deserializeEntry.
@Override
public void deserializeEntry(ByteBuf message, MatchBuilder builder) {
final boolean hasMask = processHeader(message);
// Just skip experimenter ID for now, not used
message.readUnsignedInt();
final TcpFlagsMatchBuilder tcpFlagsBuilder = new TcpFlagsMatchBuilder().setTcpFlags(message.readUnsignedShort());
if (hasMask) {
tcpFlagsBuilder.setTcpFlagsMask(message.readUnsignedShort());
}
if (Objects.isNull(builder.getTcpFlagsMatch())) {
builder.setTcpFlagsMatch(tcpFlagsBuilder.build());
} else {
throwErrorOnMalformed(builder, "tcpFlagsMatch");
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatch in project openflowplugin by opendaylight.
the class TcpFlagsEntryDeserializerTest method deserializeEntry.
@Test
public void deserializeEntry() throws Exception {
final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
final int tcpFlags = 6;
final int tcpFlagsMask = 5;
writeHeader(in, false);
in.writeInt((int) EncodeConstants.ONF_EXPERIMENTER_ID);
in.writeShort(tcpFlags);
TcpFlagsMatch match = deserialize(in).getTcpFlagsMatch();
assertEquals(tcpFlags, match.getTcpFlags().intValue());
assertEquals(0, in.readableBytes());
writeHeader(in, true);
in.writeInt((int) EncodeConstants.ONF_EXPERIMENTER_ID);
in.writeShort(tcpFlags);
in.writeShort(tcpFlagsMask);
match = deserialize(in).getTcpFlagsMatch();
assertEquals(tcpFlags, match.getTcpFlags().intValue());
assertEquals(tcpFlagsMask, match.getTcpFlagsMask().intValue());
assertEquals(0, in.readableBytes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatch in project openflowplugin by opendaylight.
the class MatchConvertor method convert.
@Override
public List<MatchEntry> convert(final Match source, final VersionConvertorData data) {
List<MatchEntry> result = new ArrayList<>();
if (source == null) {
return result;
}
final ExtensionConverterProvider extensionConvertorProvider = OFSessionUtil.getExtensionConvertorProvider();
inPortMatch(result, source.getInPort());
inPhyPortMatch(result, source.getInPhyPort());
metadataMatch(result, source.getMetadata());
ethernetMatch(result, source.getEthernetMatch());
vlanMatch(result, source.getVlanMatch());
ipMatch(result, source.getIpMatch());
layer4Match(result, source.getLayer4Match(), getConvertorExecutor(), extensionConvertorProvider);
icmpv4Match(result, source.getIcmpv4Match());
icmpv6Match(result, source.getIcmpv6Match());
layer3Match(result, source.getLayer3Match(), getConvertorExecutor(), extensionConvertorProvider);
protocolMatchFields(result, source.getProtocolMatchFields());
tunnelMatch(result, source.getTunnel());
tcpFlagsMatch(result, source.getTcpFlagsMatch());
/*
* TODO: EXTENSION PROPOSAL (source, MD-SAL to OFJava)
* - we might need version for conversion and for key
*/
Optional<GeneralExtensionListGrouping> extensionListOpt = ExtensionResolvers.getMatchExtensionResolver().getExtension(source);
if (extensionListOpt.isPresent()) {
List<ExtensionList> extensionListList = extensionListOpt.get().getExtensionList();
for (ExtensionList extensionItem : extensionListList) {
// TODO: get real version
ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionItem.getExtensionKey(), OFConstants.OFP_VERSION_1_3);
ConvertorToOFJava<MatchEntry> convertor = extensionConvertorProvider.getConverter(key);
if (convertor == null) {
throw new IllegalStateException("No converter found for key: " + key.toString());
}
MatchEntry ofMatch = convertor.convert(extensionItem.getExtension());
result.add(ofMatch);
}
}
return result;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatch in project openflowplugin by opendaylight.
the class TcpFlagsEntrySerializerTest method testSerialize.
@Test
public void testSerialize() throws Exception {
final int tcp = 8;
final byte[] tcpMask = new byte[] { 30, 30 };
final Match tcpFlagsMatch = new MatchBuilder().setTcpFlagsMatch(new TcpFlagsMatchBuilder().setTcpFlags(tcp).setTcpFlagsMask(ByteUtil.bytesToUnsignedShort(tcpMask)).build()).build();
assertMatch(tcpFlagsMatch, true, (out) -> {
assertEquals(out.readUnsignedShort(), tcp);
byte[] mask = new byte[2];
out.readBytes(mask);
assertArrayEquals(mask, tcpMask);
});
final Match tcpFlagsMatchNoMask = new MatchBuilder().setTcpFlagsMatch(new TcpFlagsMatchBuilder().setTcpFlags(tcp).build()).build();
assertMatch(tcpFlagsMatchNoMask, false, (out) -> assertEquals(out.readUnsignedShort(), tcp));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TcpFlagsMatch in project openflowplugin by opendaylight.
the class TunnelIdEntrySerializerTest method testSerialize.
@Test
public void testSerialize() throws Exception {
final long tunnelId = 8;
final byte[] tcpMask = new byte[] { 30, 30, 30, 30, 0, 0, 0, 0 };
final ByteBuffer maskBuff = ByteBuffer.allocate(Long.BYTES);
maskBuff.put(tcpMask, 0, tcpMask.length);
maskBuff.flip();
final Match tcpFlagsMatch = new MatchBuilder().setTunnel(new TunnelBuilder().setTunnelId(BigInteger.valueOf(tunnelId)).setTunnelMask(BigInteger.valueOf(maskBuff.getLong())).build()).build();
assertMatch(tcpFlagsMatch, true, (out) -> {
assertEquals(out.readLong(), tunnelId);
byte[] mask = new byte[8];
out.readBytes(mask);
assertArrayEquals(mask, tcpMask);
});
final Match tcpFlagsMatchNoMask = new MatchBuilder().setTunnel(new TunnelBuilder().setTunnelId(BigInteger.valueOf(tunnelId)).build()).build();
assertMatch(tcpFlagsMatchNoMask, false, (out) -> assertEquals(out.readLong(), tunnelId));
}
Aggregations