Hyunsun Moon

ONOS-2581 Add codec for tunnel id

Change-Id: I6ff456b0419b427945cc53fb74fd0a91cdfa758e
...@@ -60,6 +60,7 @@ public final class CriterionCodec extends JsonCodec<Criterion> { ...@@ -60,6 +60,7 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
60 protected static final String SPACING_MULIPLIER = "spacingMultiplier"; 60 protected static final String SPACING_MULIPLIER = "spacingMultiplier";
61 protected static final String SLOT_GRANULARITY = "slotGranularity"; 61 protected static final String SLOT_GRANULARITY = "slotGranularity";
62 protected static final String OCH_SIGNAL_ID = "ochSignalId"; 62 protected static final String OCH_SIGNAL_ID = "ochSignalId";
63 + protected static final String TUNNEL_ID = "tunnelId";
63 64
64 @Override 65 @Override
65 public ObjectNode encode(Criterion criterion, CodecContext context) { 66 public ObjectNode encode(Criterion criterion, CodecContext context) {
......
...@@ -93,6 +93,7 @@ public final class DecodeCriterionCodecHelper { ...@@ -93,6 +93,7 @@ public final class DecodeCriterionCodecHelper {
93 decoderMap.put(Criterion.Type.IPV6_EXTHDR.name(), new IpV6ExthdrDecoder()); 93 decoderMap.put(Criterion.Type.IPV6_EXTHDR.name(), new IpV6ExthdrDecoder());
94 decoderMap.put(Criterion.Type.OCH_SIGID.name(), new OchSigIdDecoder()); 94 decoderMap.put(Criterion.Type.OCH_SIGID.name(), new OchSigIdDecoder());
95 decoderMap.put(Criterion.Type.OCH_SIGTYPE.name(), new OchSigTypeDecoder()); 95 decoderMap.put(Criterion.Type.OCH_SIGTYPE.name(), new OchSigTypeDecoder());
96 + decoderMap.put(Criterion.Type.TUNNEL_ID.name(), new TunnelIdDecoder());
96 } 97 }
97 98
98 private class EthTypeDecoder implements CriterionDecoder { 99 private class EthTypeDecoder implements CriterionDecoder {
...@@ -417,6 +418,15 @@ public final class DecodeCriterionCodecHelper { ...@@ -417,6 +418,15 @@ public final class DecodeCriterionCodecHelper {
417 } 418 }
418 } 419 }
419 420
421 + private class TunnelIdDecoder implements CriterionDecoder {
422 + @Override
423 + public Criterion decodeCriterion(ObjectNode json) {
424 + long tunnelId = nullIsIllegal(json.get(CriterionCodec.TUNNEL_ID),
425 + CriterionCodec.TUNNEL_ID + MISSING_MEMBER_MESSAGE).asLong();
426 + return Criteria.matchTunnelId(tunnelId);
427 + }
428 + }
429 +
420 /** 430 /**
421 * Decodes the JSON into a criterion object. 431 * Decodes the JSON into a criterion object.
422 * 432 *
......
...@@ -88,6 +88,10 @@ public final class DecodeInstructionCodecHelper { ...@@ -88,6 +88,10 @@ public final class DecodeInstructionCodecHelper {
88 return Instructions.popVlan(); 88 return Instructions.popVlan();
89 } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_PUSH.name())) { 89 } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_PUSH.name())) {
90 return Instructions.pushVlan(); 90 return Instructions.pushVlan();
91 + } else if (subType.equals(L2ModificationInstruction.L2SubType.TUNNEL_ID.name())) {
92 + long tunnelId = nullIsIllegal(json.get(InstructionCodec.TUNNEL_ID),
93 + InstructionCodec.TUNNEL_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asLong();
94 + return Instructions.modTunnelId(tunnelId);
91 } 95 }
92 throw new IllegalArgumentException("L2 Instruction subtype " 96 throw new IllegalArgumentException("L2 Instruction subtype "
93 + subType + " is not supported"); 97 + subType + " is not supported");
......
...@@ -41,6 +41,7 @@ import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; ...@@ -41,6 +41,7 @@ import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
41 import org.onosproject.net.flow.criteria.PortCriterion; 41 import org.onosproject.net.flow.criteria.PortCriterion;
42 import org.onosproject.net.flow.criteria.SctpPortCriterion; 42 import org.onosproject.net.flow.criteria.SctpPortCriterion;
43 import org.onosproject.net.flow.criteria.TcpPortCriterion; 43 import org.onosproject.net.flow.criteria.TcpPortCriterion;
44 +import org.onosproject.net.flow.criteria.TunnelIdCriterion;
44 import org.onosproject.net.flow.criteria.UdpPortCriterion; 45 import org.onosproject.net.flow.criteria.UdpPortCriterion;
45 import org.onosproject.net.flow.criteria.VlanIdCriterion; 46 import org.onosproject.net.flow.criteria.VlanIdCriterion;
46 import org.onosproject.net.flow.criteria.VlanPcpCriterion; 47 import org.onosproject.net.flow.criteria.VlanPcpCriterion;
...@@ -105,6 +106,7 @@ public final class EncodeCriterionCodecHelper { ...@@ -105,6 +106,7 @@ public final class EncodeCriterionCodecHelper {
105 formatMap.put(Criterion.Type.IPV6_EXTHDR, new FormatIpV6Exthdr()); 106 formatMap.put(Criterion.Type.IPV6_EXTHDR, new FormatIpV6Exthdr());
106 formatMap.put(Criterion.Type.OCH_SIGID, new FormatOchSigId()); 107 formatMap.put(Criterion.Type.OCH_SIGID, new FormatOchSigId());
107 formatMap.put(Criterion.Type.OCH_SIGTYPE, new FormatOchSigType()); 108 formatMap.put(Criterion.Type.OCH_SIGTYPE, new FormatOchSigType());
109 + formatMap.put(Criterion.Type.TUNNEL_ID, new FormatTunnelId());
108 formatMap.put(Criterion.Type.DUMMY, new FormatDummyType()); 110 formatMap.put(Criterion.Type.DUMMY, new FormatDummyType());
109 111
110 // Currently unimplemented 112 // Currently unimplemented
...@@ -116,7 +118,6 @@ public final class EncodeCriterionCodecHelper { ...@@ -116,7 +118,6 @@ public final class EncodeCriterionCodecHelper {
116 formatMap.put(Criterion.Type.MPLS_TC, new FormatUnknown()); 118 formatMap.put(Criterion.Type.MPLS_TC, new FormatUnknown());
117 formatMap.put(Criterion.Type.MPLS_BOS, new FormatUnknown()); 119 formatMap.put(Criterion.Type.MPLS_BOS, new FormatUnknown());
118 formatMap.put(Criterion.Type.PBB_ISID, new FormatUnknown()); 120 formatMap.put(Criterion.Type.PBB_ISID, new FormatUnknown());
119 - formatMap.put(Criterion.Type.TUNNEL_ID, new FormatUnknown());
120 formatMap.put(Criterion.Type.UNASSIGNED_40, new FormatUnknown()); 121 formatMap.put(Criterion.Type.UNASSIGNED_40, new FormatUnknown());
121 formatMap.put(Criterion.Type.PBB_UCA, new FormatUnknown()); 122 formatMap.put(Criterion.Type.PBB_UCA, new FormatUnknown());
122 formatMap.put(Criterion.Type.TCP_FLAGS, new FormatUnknown()); 123 formatMap.put(Criterion.Type.TCP_FLAGS, new FormatUnknown());
...@@ -354,6 +355,15 @@ public final class EncodeCriterionCodecHelper { ...@@ -354,6 +355,15 @@ public final class EncodeCriterionCodecHelper {
354 } 355 }
355 } 356 }
356 357
358 + private static class FormatTunnelId implements CriterionTypeFormatter {
359 + @Override
360 + public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
361 + final TunnelIdCriterion tunnelIdCriterion =
362 + (TunnelIdCriterion) criterion;
363 + return root.put(CriterionCodec.TUNNEL_ID, tunnelIdCriterion.tunnelId());
364 + }
365 + }
366 +
357 private class FormatDummyType implements CriterionTypeFormatter { 367 private class FormatDummyType implements CriterionTypeFormatter {
358 368
359 @Override 369 @Override
......
...@@ -123,6 +123,12 @@ public final class EncodeInstructionCodecHelper { ...@@ -123,6 +123,12 @@ public final class EncodeInstructionCodecHelper {
123 pushHeaderInstructions.ethernetType().toShort()); 123 pushHeaderInstructions.ethernetType().toShort());
124 break; 124 break;
125 125
126 + case TUNNEL_ID:
127 + final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction =
128 + (L2ModificationInstruction.ModTunnelIdInstruction) instruction;
129 + result.put(InstructionCodec.TUNNEL_ID, modTunnelIdInstruction.tunnelId());
130 + break;
131 +
126 default: 132 default:
127 log.info("Cannot convert L2 subtype of {}", instruction.subtype()); 133 log.info("Cannot convert L2 subtype of {}", instruction.subtype());
128 break; 134 break;
......
...@@ -47,6 +47,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> { ...@@ -47,6 +47,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> {
47 protected static final String SPACING_MULTIPLIER = "spacingMultiplier"; 47 protected static final String SPACING_MULTIPLIER = "spacingMultiplier";
48 protected static final String SLOT_GRANULARITY = "slotGranularity"; 48 protected static final String SLOT_GRANULARITY = "slotGranularity";
49 protected static final String ETHERNET_TYPE = "ethernetType"; 49 protected static final String ETHERNET_TYPE = "ethernetType";
50 + protected static final String TUNNEL_ID = "tunnelId";
50 51
51 protected static final String MISSING_MEMBER_MESSAGE = 52 protected static final String MISSING_MEMBER_MESSAGE =
52 " member is required in Instruction"; 53 " member is required in Instruction";
......
...@@ -58,6 +58,7 @@ import org.onosproject.net.flow.criteria.OchSignalCriterion; ...@@ -58,6 +58,7 @@ import org.onosproject.net.flow.criteria.OchSignalCriterion;
58 import org.onosproject.net.flow.criteria.PortCriterion; 58 import org.onosproject.net.flow.criteria.PortCriterion;
59 import org.onosproject.net.flow.criteria.SctpPortCriterion; 59 import org.onosproject.net.flow.criteria.SctpPortCriterion;
60 import org.onosproject.net.flow.criteria.TcpPortCriterion; 60 import org.onosproject.net.flow.criteria.TcpPortCriterion;
61 +import org.onosproject.net.flow.criteria.TunnelIdCriterion;
61 import org.onosproject.net.flow.criteria.UdpPortCriterion; 62 import org.onosproject.net.flow.criteria.UdpPortCriterion;
62 import org.onosproject.net.flow.criteria.VlanIdCriterion; 63 import org.onosproject.net.flow.criteria.VlanIdCriterion;
63 import org.onosproject.net.flow.criteria.VlanPcpCriterion; 64 import org.onosproject.net.flow.criteria.VlanPcpCriterion;
...@@ -205,7 +206,7 @@ public class FlowRuleCodecTest { ...@@ -205,7 +206,7 @@ public class FlowRuleCodecTest {
205 instruction.type().name() + "/" + subType, instruction); 206 instruction.type().name() + "/" + subType, instruction);
206 }); 207 });
207 208
208 - assertThat(rule.treatment().allInstructions().size(), is(19)); 209 + assertThat(rule.treatment().allInstructions().size(), is(20));
209 210
210 Instruction instruction; 211 Instruction instruction;
211 212
...@@ -273,6 +274,12 @@ public class FlowRuleCodecTest { ...@@ -273,6 +274,12 @@ public class FlowRuleCodecTest {
273 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION)); 274 assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
274 assertThat(instruction, instanceOf(L2ModificationInstruction.PushHeaderInstructions.class)); 275 assertThat(instruction, instanceOf(L2ModificationInstruction.PushHeaderInstructions.class));
275 276
277 + instruction = getInstruction(Instruction.Type.L2MODIFICATION,
278 + L2ModificationInstruction.L2SubType.TUNNEL_ID.name());
279 + assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
280 + assertThat(((L2ModificationInstruction.ModTunnelIdInstruction) instruction)
281 + .tunnelId(), is(100L));
282 +
276 instruction = getInstruction(Instruction.Type.L3MODIFICATION, 283 instruction = getInstruction(Instruction.Type.L3MODIFICATION,
277 L3ModificationInstruction.L3SubType.IPV4_SRC.name()); 284 L3ModificationInstruction.L3SubType.IPV4_SRC.name());
278 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION)); 285 assertThat(instruction.type(), is(Instruction.Type.L3MODIFICATION));
...@@ -347,7 +354,7 @@ public class FlowRuleCodecTest { ...@@ -347,7 +354,7 @@ public class FlowRuleCodecTest {
347 354
348 checkCommonData(rule); 355 checkCommonData(rule);
349 356
350 - assertThat(rule.selector().criteria().size(), is(32)); 357 + assertThat(rule.selector().criteria().size(), is(33));
351 358
352 rule.selector().criteria() 359 rule.selector().criteria()
353 .stream() 360 .stream()
...@@ -479,6 +486,10 @@ public class FlowRuleCodecTest { ...@@ -479,6 +486,10 @@ public class FlowRuleCodecTest {
479 criterion = getCriterion(Criterion.Type.OCH_SIGID); 486 criterion = getCriterion(Criterion.Type.OCH_SIGID);
480 assertThat(((IndexedLambdaCriterion) criterion).lambda(), 487 assertThat(((IndexedLambdaCriterion) criterion).lambda(),
481 is(Lambda.indexedLambda(122))); 488 is(Lambda.indexedLambda(122)));
489 +
490 + criterion = getCriterion(Criterion.Type.TUNNEL_ID);
491 + assertThat(((TunnelIdCriterion) criterion).tunnelId(),
492 + is(100L));
482 } 493 }
483 494
484 /** 495 /**
......
...@@ -37,7 +37,8 @@ ...@@ -37,7 +37,8 @@
37 {"type":"IPV6_ND_TLL", "mac":"00:11:22:33:44:57"}, 37 {"type":"IPV6_ND_TLL", "mac":"00:11:22:33:44:57"},
38 {"type":"MPLS_LABEL", "label":123}, 38 {"type":"MPLS_LABEL", "label":123},
39 {"type":"IPV6_EXTHDR", "exthdrFlags":99}, 39 {"type":"IPV6_EXTHDR", "exthdrFlags":99},
40 - {"type":"OCH_SIGID", "lambda":122} 40 + {"type":"OCH_SIGID", "lambda":122},
41 + {"type":"TUNNEL_ID", "tunnelId":100}
41 ] 42 ]
42 } 43 }
43 } 44 }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 {"type":"L2MODIFICATION","subtype":"DEC_MPLS_TTL"}, 19 {"type":"L2MODIFICATION","subtype":"DEC_MPLS_TTL"},
20 {"type":"L2MODIFICATION","subtype":"VLAN_POP"}, 20 {"type":"L2MODIFICATION","subtype":"VLAN_POP"},
21 {"type":"L2MODIFICATION","subtype":"VLAN_PUSH"}, 21 {"type":"L2MODIFICATION","subtype":"VLAN_PUSH"},
22 + {"type":"L2MODIFICATION","subtype":"TUNNEL_ID", "tunnelId":100},
22 {"type":"L3MODIFICATION","subtype":"IPV4_SRC", "ip":"1.2.3.4"}, 23 {"type":"L3MODIFICATION","subtype":"IPV4_SRC", "ip":"1.2.3.4"},
23 {"type":"L3MODIFICATION","subtype":"IPV4_DST", "ip":"1.2.3.3"}, 24 {"type":"L3MODIFICATION","subtype":"IPV4_DST", "ip":"1.2.3.3"},
24 {"type":"L3MODIFICATION","subtype":"IPV6_SRC", "ip":"1.2.3.2"}, 25 {"type":"L3MODIFICATION","subtype":"IPV6_SRC", "ip":"1.2.3.2"},
......