import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntry.PseudoField;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.StandardMatchType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
import com.google.common.base.Joiner;
*/
public abstract class MatchDeserializer {
- private static final Logger LOGGER = LoggerFactory.getLogger(MatchDeserializer.class);
-
/**
* Creates match
* @param in input ByteBuf
}
return null;
}
-
+
/**
* Deserializes single match entry (oxm_field)
* @param in input ByteBuf
public static List<MatchEntries> createMatchEntry(ByteBuf in, int matchLength) {
return createMatchEntriesInternal(in, matchLength, true);
}
-
+
/**
* @param in input ByteBuf
* @param matchLength length of match entries
public static List<MatchEntries> createMatchEntries(ByteBuf in, int matchLength) {
return createMatchEntriesInternal(in, matchLength, false);
}
-
+
private static List<MatchEntries> createMatchEntriesInternal(ByteBuf in, int matchLength, boolean oneEntry) {
List<MatchEntries> matchEntriesList = new ArrayList<>();
int currLength = 0;
while(currLength < matchLength) {
- MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
- switch (in.readUnsignedShort()) {
+ MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
+ switch (in.readUnsignedShort()) {
case 0x0000:
matchEntriesBuilder.setOxmClass(Nxm0Class.class);
break;
int matchEntryLength = in.readUnsignedByte();
currLength += EncodeConstants.SIZE_OF_SHORT_IN_BYTES +
(2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES) + matchEntryLength;
-
+
switch(matchField) {
- case 0:
+ case 0:
matchEntriesBuilder.setOxmMatchField(InPort.class);
PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
- port.setPortNumber(new PortNumber(in.readUnsignedInt()));
+ port.setPortNumber(new PortNumber(in.readUnsignedInt()));
matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
break;
case 1:
matchEntriesBuilder.setOxmMatchField(InPhyPort.class);
PortNumberMatchEntryBuilder phyPort = new PortNumberMatchEntryBuilder();
- phyPort.setPortNumber(new PortNumber(in.readUnsignedInt()));
+ phyPort.setPortNumber(new PortNumber(in.readUnsignedInt()));
matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, phyPort.build());
break;
case 2:
matchEntriesBuilder.setOxmMatchField(EthDst.class);
addMacAddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
- addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
+ addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH);
}
break;
case 4:
matchEntriesBuilder.setOxmMatchField(EthSrc.class);
addMacAddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
- addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
+ addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH);
}
break;
case 5:
break;
case 11:
matchEntriesBuilder.setOxmMatchField(Ipv4Src.class);
- LOGGER.warn("IPV4address(ipv4src): received but possible wrong deserialization");
addIpv4AddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
break;
case 12:
matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class);
- LOGGER.warn("IPV4address(ipv4dst): received but possible wrong deserialization");
addIpv4AddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
break;
case 13:
matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
- addPortAugmentation(null, in);
+ addPortAugmentation(matchEntriesBuilder, in);
break;
case 14:
matchEntriesBuilder.setOxmMatchField(TcpDst.class);
- addPortAugmentation(null, in);
+ addPortAugmentation(matchEntriesBuilder, in);
break;
case 15:
matchEntriesBuilder.setOxmMatchField(UdpSrc.class);
- addPortAugmentation(null, in);
+ addPortAugmentation(matchEntriesBuilder, in);
break;
case 16:
matchEntriesBuilder.setOxmMatchField(UdpDst.class);
- addPortAugmentation(null, in);
+ addPortAugmentation(matchEntriesBuilder, in);
break;
case 17:
matchEntriesBuilder.setOxmMatchField(SctpSrc.class);
- addPortAugmentation(null, in);
+ addPortAugmentation(matchEntriesBuilder, in);
break;
case 18:
matchEntriesBuilder.setOxmMatchField(SctpDst.class);
- addPortAugmentation(null, in);
+ addPortAugmentation(matchEntriesBuilder, in);
break;
case 19:
matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
break;
case 22:
matchEntriesBuilder.setOxmMatchField(ArpSpa.class);
- LOGGER.warn("IPV4address(arpspa): received but possible wrong deserialization");
addIpv4AddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
break;
case 23:
matchEntriesBuilder.setOxmMatchField(ArpTpa.class);
- LOGGER.warn("IPV4address(arptpa): received but possible wrong deserialization");
addIpv4AddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
matchEntriesBuilder.setOxmMatchField(ArpSha.class);
addMacAddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
- addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
+ addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH);
}
break;
case 25:
matchEntriesBuilder.setOxmMatchField(ArpTha.class);
addMacAddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
- addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
+ addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH);
}
break;
case 26:
matchEntriesBuilder.setOxmMatchField(Ipv6Src.class);
- // TODO - ipv6address - check format with tests
- LOGGER.warn("IPV6address(Ipv6Src): received but possible wrong deserialization");
addIpv6AddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);
break;
case 27:
matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class);
- // TODO - ipv6address - check format with tests
- LOGGER.warn("IPV6address(Ipv6Dst): received but possible wrong deserialization");
addIpv6AddressAugmentation(matchEntriesBuilder, in);
if (hasMask) {
addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);
break;
case 31:
matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
- // TODO - ipv6address - check format with tests
- LOGGER.warn("IPV6address(Ipv6NdTarget): received but possible wrong deserialization");
addIpv6AddressAugmentation(matchEntriesBuilder, in);
break;
case 32:
case 37:
matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
- isidBuilder.setIsid(in.readUnsignedInt());
+ Integer isid = in.readUnsignedMedium();
+ isidBuilder.setIsid(isid.longValue());
matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
if (hasMask) {
- addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
+ addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_3_BYTES);
}
break;
case 38:
final Boolean HOP = ((bitmap) & (1<<6)) != 0;
final Boolean UNREP = ((bitmap) & (1<<7)) != 0;
final Boolean UNSEQ = ((bitmap) & (1<<8)) != 0;
- pseudoBuilder.setPseudoField(new PseudoField(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
+ pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
if (hasMask) {
addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
}
break;
- default:
+ default:
break;
}
matchEntriesList.add(matchEntriesBuilder.build());
return matchEntriesList;
}
+ /** Decodes oxm ids
+ * @param in input ByteBuf
+ * @param matchLength match entries length
+ * @return list of match ids
+ */
+ public static List<MatchEntries> createMatchIds(ByteBuf in, int matchLength) {
+ return MatchIdsDeserializer.createOxmIds(in, matchLength);
+ }
+
private static void addMaskAugmentation(MatchEntriesBuilder builder, ByteBuf in, int matchEntryLength) {
MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
byte[] mask = new byte[matchEntryLength];
Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
List<String> groups = new ArrayList<>();
for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV6_ADDRESS; i++) {
- groups.add(String.format("X", in.readUnsignedShort()));
+ groups.add(String.format("%04X", in.readUnsignedShort()));
}
Joiner joiner = Joiner.on(":");
ipv6AddressBuilder.setIpv6Address(new Ipv6Address(joiner.join(groups)));
builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
}
-
+
private static void addMetadataAugmentation(MatchEntriesBuilder builder, ByteBuf in) {
MetadataMatchEntryBuilder metadata = new MetadataMatchEntryBuilder();
- byte[] metadataBytes = new byte[Long.SIZE/Byte.SIZE];
+ byte[] metadataBytes = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
in.readBytes(metadataBytes);
- metadata.setMetadata(metadataBytes);
+ metadata.setMetadata(metadataBytes);
builder.addAugmentation(MetadataMatchEntry.class, metadata.build());
}
macAddress.setMacAddress(new MacAddress(ByteBufUtils.macAddressToString(address)));
builder.addAugmentation(MacAddressMatchEntry.class, macAddress.build());
}
-
+
private static void addPortAugmentation(MatchEntriesBuilder builder, ByteBuf in) {
PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
portBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.