import io.netty.buffer.ByteBuf;
-import java.util.HashMap;
-import java.util.Map;
-
import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
* @param match match to be serialized
*/
@Override
- public void serialize(MatchV10 match, ByteBuf outBuffer) {
+ public void serialize(final MatchV10 match, final ByteBuf outBuffer) {
outBuffer.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask()));
outBuffer.writeShort(match.getInPort());
outBuffer.writeBytes(ByteBufUtils.macAddressToBytes(match.getDlSrc().getValue()));
outBuffer.writeByte(match.getNwTos());
outBuffer.writeByte(match.getNwProto());
ByteBufUtils.padBuffer(PADDING_IN_MATCH_2, outBuffer);
- String[] srcGroups = match.getNwSrc().getValue().split("\\.");
- for (int i = 0; i < srcGroups.length; i++) {
- outBuffer.writeByte(Integer.parseInt(srcGroups[i]));
+ Iterable<String> srcGroups = ByteBufUtils.DOT_SPLITTER.split(match.getNwSrc().getValue());
+ for (String group : srcGroups) {
+ outBuffer.writeByte(Short.parseShort(group));
}
- String[] dstGroups = match.getNwDst().getValue().split("\\.");
- for (int i = 0; i < dstGroups.length; i++) {
- outBuffer.writeByte(Integer.parseInt(dstGroups[i]));
+ Iterable<String> dstGroups = ByteBufUtils.DOT_SPLITTER.split(match.getNwDst().getValue());
+ for (String group : dstGroups) {
+ outBuffer.writeByte(Short.parseShort(group));
}
outBuffer.writeShort(match.getTpSrc());
outBuffer.writeShort(match.getTpDst());
}
- private static int encodeWildcards(FlowWildcardsV10 wildcards, short srcMask, short dstMask) {
- int bitmask = 0;
- Map<Integer, Boolean> wildcardsMap = new HashMap<>();
- wildcardsMap.put(0, wildcards.isINPORT());
- wildcardsMap.put(1, wildcards.isDLVLAN());
- wildcardsMap.put(2, wildcards.isDLSRC());
- wildcardsMap.put(3, wildcards.isDLDST());
- wildcardsMap.put(4, wildcards.isDLTYPE());
- wildcardsMap.put(5, wildcards.isNWPROTO());
- wildcardsMap.put(6, wildcards.isTPSRC());
- wildcardsMap.put(7, wildcards.isTPDST());
- wildcardsMap.put(20, wildcards.isDLVLANPCP());
- wildcardsMap.put(21, wildcards.isNWTOS());
- bitmask = ByteBufUtils.fillBitMaskFromMap(wildcardsMap);
+ private static int encodeWildcards(final FlowWildcardsV10 wildcards, final short srcMask, final short dstMask) {
+ int bitmask = ByteBufUtils.fillBitMask(0,
+ wildcards.isINPORT(),
+ wildcards.isDLVLAN(),
+ wildcards.isDLSRC(),
+ wildcards.isDLDST(),
+ wildcards.isDLTYPE(),
+ wildcards.isNWPROTO(),
+ wildcards.isTPSRC(),
+ wildcards.isTPDST());
+ bitmask |= ByteBufUtils.fillBitMask(20,
+ wildcards.isDLVLANPCP(),
+ wildcards.isNWTOS());
bitmask |= ((32 - srcMask) << NW_SRC_SHIFT);
bitmask |= ((32 - dstMask) << NW_DST_SHIFT);
return bitmask;