- Fixed MatchType class to allow the value 0 on VLAN ID field for VLAN untagged frames.
- Changed FlowConverter class to convert the value 0 on VLAN ID field of SAL Flow into the value 0xffff of OF Flow, and vice-versa.
Signed-off-by: Hideyuki Tai <h-tai@cd.jp.nec.com>
public class FlowConverter {
protected static final Logger logger = LoggerFactory
.getLogger(FlowConverter.class);
+
+ /*
+ * The value 0xffff (OFP_VLAN_NONE) is used to indicate
+ * that no VLAN ID is set for OF Flow.
+ */
+ private static final short OFP_VLAN_NONE = (short) 0xffff;
+
private Flow flow; // SAL Flow
private OFMatch ofMatch; // OF 1.0 match or OF 1.0 + IPv6 extension match
private List<OFAction> actionsList; // OF 1.0 actions
if (match.isPresent(MatchType.DL_VLAN)) {
short vlan = (Short) match.getField(MatchType.DL_VLAN)
.getValue();
+ if (vlan == MatchType.DL_VLAN_NONE) {
+ vlan = OFP_VLAN_NONE;
+ }
if (!isIPv6) {
ofMatch.setDataLayerVirtualLan(vlan);
wildcards &= ~OFMatch.OFPFW_DL_VLAN;
salMatch.setField(new MatchField(MatchType.DL_TYPE,
ofMatch.getDataLayerType()));
}
- if (ofMatch.getDataLayerVirtualLan() != 0) {
+ short vlan = ofMatch.getDataLayerVirtualLan();
+ if (vlan != 0) {
+ if (vlan == OFP_VLAN_NONE) {
+ vlan = MatchType.DL_VLAN_NONE;
+ }
salMatch.setField(new MatchField(MatchType.DL_VLAN,
- ofMatch.getDataLayerVirtualLan()));
+ vlan));
}
if (ofMatch.getDataLayerVirtualLanPriorityCodePoint() != 0) {
salMatch.setField(MatchType.DL_VLAN_PR, ofMatch
salMatch.setField(new MatchField(MatchType.DL_TYPE,
v6Match.getDataLayerType()));
}
- if (v6Match.getDataLayerVirtualLan() != 0) {
+ short vlan = v6Match.getDataLayerVirtualLan();
+ if (vlan != 0) {
+ if (vlan == OFP_VLAN_NONE) {
+ vlan = MatchType.DL_VLAN_NONE;
+ }
salMatch.setField(new MatchField(MatchType.DL_VLAN,
- v6Match.getDataLayerVirtualLan()));
+ vlan));
}
if (v6Match.getDataLayerVirtualLanPriorityCodePoint() != 0) {
salMatch.setField(MatchType.DL_VLAN_PR, v6Match
}
}
+ @Test
+ public void testVlanNoneIdFlowConversion() throws Exception {
+ Node node = NodeCreator.createOFNode(1000l);
+
+ /*
+ * The value 0 is used to indicate that no VLAN ID is set
+ * for SAL Flow.
+ */
+ short vlan = (short) 0;
+
+ /*
+ * Create a SAL Flow aFlow
+ */
+ Match match = new Match();
+ match.setField(MatchType.DL_VLAN, vlan);
+
+ List<Action> actions = new ArrayList<Action>();
+
+ Flow aFlow = new Flow(match, actions);
+
+ /*
+ * Convert the SAL aFlow to OF Flow
+ */
+ FlowConverter salToOF = new FlowConverter(aFlow);
+ OFMatch ofMatch = salToOF.getOFMatch();
+ List<OFAction> ofActions = salToOF.getOFActions();
+
+ /*
+ * The value 0xffff (OFP_VLAN_NONE) is used to indicate
+ * that no VLAN ID is set for OF Flow.
+ */
+ Assert.assertEquals((short) 0xffff, ofMatch.getDataLayerVirtualLan());
+
+ /*
+ * Convert the OF Flow to SAL Flow bFlow
+ */
+ FlowConverter ofToSal = new FlowConverter(ofMatch, ofActions);
+ Flow bFlow = ofToSal.getFlow(node);
+ Match bMatch = bFlow.getMatch();
+
+ /*
+ * Verify the converted SAL flow bFlow is equivalent to the original SAL Flow
+ */
+ Assert
+ .assertTrue(((Short) match.getField(MatchType.DL_VLAN)
+ .getValue()).equals((Short) bMatch.getField(
+ MatchType.DL_VLAN).getValue()));
+ }
+
@Test
public void testV6toSALFlowConversion() throws Exception {
Node node = NodeCreator.createOFNode(12l);
IN_PORT("inPort", 1 << 0, NodeConnector.class, 1, 0),
DL_SRC("dlSrc", 1 << 1, Byte[].class, 0, 0xffffffffffffL),
DL_DST("dlDst", 1 << 2, Byte[].class, 0, 0xffffffffffffL),
- DL_VLAN("dlVlan", 1 << 3, Short.class, 1, 0xfff), // 2 bytes
+ DL_VLAN("dlVlan", 1 << 3, Short.class, 0, 0xfff), // 2 bytes
DL_VLAN_PR("dlVlanPriority", 1 << 4, Byte.class, 0, 0x7), // 3 bits
DL_OUTER_VLAN("dlOuterVlan", 1 << 5, Short.class, 1, 0xfff),
DL_OUTER_VLAN_PR("dlOuterVlanPriority", 1 << 6, Short.class, 0, 0x7),
TP_SRC("tpSrc", 1 << 12, Short.class, 1, 0xffff), // 2 bytes
TP_DST("tpDst", 1 << 13, Short.class, 1, 0xffff); // 2 bytes
+ // Used to indicate that no VLAN ID is set.
+ public static final short DL_VLAN_NONE = (short) 0;
+
private String id;
private int index;
private Class<?> dataType;
Assert.assertTrue(flipflip.equals(flipped));
}
+
+ @Test
+ public void testVlanNone() throws Exception {
+ // The value 0 is used to indicate that no VLAN ID is set
+ short vlan = (short) 0;
+ MatchField field = new MatchField(MatchType.DL_VLAN, vlan);
+
+ Assert.assertTrue(field != null);
+ Assert.assertTrue(field.getValue().equals(new Short(vlan)));
+ Assert.assertTrue(field.isValid());
+ }
}