type bits {
bit IN_PORT {
position 0;
- /* Switch input port. */
}
bit DL_VLAN {
position 1;
- /* Switch input port. */
}
bit DL_SRC {
position 2;
- /* Switch input port. */
}
bit DL_DST {
position 3;
- /* Switch input port. */
}
bit DL_TYPE {
position 4;
- /* Switch input port. */
}
bit NW_PROTO {
position 5;
- /* Switch input port. */
}
bit TP_SRC {
position 6;
- /* Switch input port. */
}
bit TP_DST {
position 7;
- /* Switch input port. */
}
bit DL_VLAN_PCP {
position 20;
- /* Switch input port. */
}
bit NW_TOS {
position 21;
- /* Switch input port. */
- }
- bit ALL {
- position 22;
- /* Switch input port. */
}
}
}
boolean _tPDST = (input & (1 << 7)) != 0;
boolean _dLVLANPCP = (input & (1 << 20)) != 0;
boolean _nWTOS = (input & (1 << 21)) != 0;
- int allBits = (1 << 22) - 1;
- boolean _aLL = (input & allBits) == allBits;
- return new FlowWildcardsV10(_aLL, _dLDST, _dLSRC, _dLTYPE, _dLVLAN,
+ return new FlowWildcardsV10(_dLDST, _dLSRC, _dLTYPE, _dLVLAN,
_dLVLANPCP, _iNPORT, _nWPROTO, _nWTOS, _tPDST, _tPSRC);
}
private static final byte PADDING_IN_MATCH_2 = 2;
private static final byte NW_SRC_SHIFT = 8;
private static final byte NW_DST_SHIFT = 14;
- private static final int ALL = ((1 << 22) - 1);
/**
* Encodes ofp_match (OpenFlow v1.0)
private static int encodeWildcards(FlowWildcardsV10 wildcards, short srcMask, short dstMask) {
int bitmask = 0;
- if (wildcards.isALL()) {
- bitmask |= ALL;
- } else {
- 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);
- bitmask |= ((32 - srcMask) << NW_SRC_SHIFT);
- bitmask |= ((32 - dstMask) << NW_DST_SHIFT);
- }
+ 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);
+ bitmask |= ((32 - srcMask) << NW_SRC_SHIFT);
+ bitmask |= ((32 - dstMask) << NW_DST_SHIFT);
return bitmask;
}
FlowModInputBuilder builder = new FlowModInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
MatchV10Builder matchBuilder = new MatchV10Builder();
- matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true, true));
+ matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
matchBuilder.setNwSrcMask((short) 0);
matchBuilder.setNwDstMask((short) 0);
matchBuilder.setInPort(58);
factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
BufferHelper.checkHeaderV10(out, factory.getMessageType(), factory.computeLength(message));
- Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt());
+ Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
Assert.assertEquals("Wrong inPort", 58, out.readUnsignedShort());
byte[] dlSrc = new byte[6];
out.readBytes(dlSrc);
+ "50 50 20 20");
message.skipBytes(4); // skip XID
MatchV10 match = OF10MatchDeserializer.createMatchV10(message);
- Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, false, true, false,
+ Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, true, false,
false, true, false, true, true, false), match.getWildcards());
Assert.assertEquals("Wrong srcMask", 24, match.getNwSrcMask().shortValue());
Assert.assertEquals("Wrong dstMask", 16, match.getNwDstMask().shortValue());
+ "50 50 20 20");
message.skipBytes(4); // skip XID
MatchV10 match = OF10MatchDeserializer.createMatchV10(message);
- Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true, true,
+ Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(true, true, true, true,
true, true, true, true, true, true), match.getWildcards());
Assert.assertEquals("Wrong srcMask", 0, match.getNwSrcMask().shortValue());
Assert.assertEquals("Wrong dstMask", 0, match.getNwDstMask().shortValue());
public void test() {
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
MatchV10Builder builder = new MatchV10Builder();
- builder.setWildcards(new FlowWildcardsV10(false, false, false, true, false,
+ builder.setWildcards(new FlowWildcardsV10(false, false, true, false,
false, true, false, true, true, true));
builder.setNwSrcMask((short) 24);
builder.setNwDstMask((short) 16);
public void test2() {
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
MatchV10Builder builder = new MatchV10Builder();
- builder.setWildcards(new FlowWildcardsV10(true, true, true, true, true,
+ builder.setWildcards(new FlowWildcardsV10(true, true, true, true,
true, true, true, true, true, true));
builder.setNwSrcMask((short) 0);
builder.setNwDstMask((short) 0);
MatchV10 match = builder.build();
OF10MatchSerializer.encodeMatchV10(out, match);
- Assert.assertEquals("Wrong wildcards", 4194303, out.readUnsignedInt());
+ Assert.assertEquals("Wrong wildcards", 3678463, out.readUnsignedInt());
Assert.assertEquals("Wrong in-port", 6653, out.readUnsignedShort());
byte[] dlSrc = new byte[6];
out.readBytes(dlSrc);