Jian Li
Committed by Gerrit Code Review

Support to specify Ofdpa extension through REST API

Code clean up for Nicira extension codec.

Change-Id: Idbbfd1ca12b01d46e3b6c90ebce39e6a6605cb58
...@@ -30,6 +30,8 @@ import org.onosproject.driver.extensions.NiciraSetNshContextHeader; ...@@ -30,6 +30,8 @@ import org.onosproject.driver.extensions.NiciraSetNshContextHeader;
30 import org.onosproject.driver.extensions.NiciraSetNshSi; 30 import org.onosproject.driver.extensions.NiciraSetNshSi;
31 import org.onosproject.driver.extensions.NiciraSetNshSpi; 31 import org.onosproject.driver.extensions.NiciraSetNshSpi;
32 import org.onosproject.driver.extensions.NiciraSetTunnelDst; 32 import org.onosproject.driver.extensions.NiciraSetTunnelDst;
33 +import org.onosproject.driver.extensions.OfdpaMatchVlanVid;
34 +import org.onosproject.driver.extensions.OfdpaSetVlanVid;
33 import org.onosproject.driver.extensions.codec.MoveExtensionTreatmentCodec; 35 import org.onosproject.driver.extensions.codec.MoveExtensionTreatmentCodec;
34 import org.onosproject.driver.extensions.codec.NiciraMatchNshSiCodec; 36 import org.onosproject.driver.extensions.codec.NiciraMatchNshSiCodec;
35 import org.onosproject.driver.extensions.codec.NiciraMatchNshSpiCodec; 37 import org.onosproject.driver.extensions.codec.NiciraMatchNshSpiCodec;
...@@ -39,6 +41,8 @@ import org.onosproject.driver.extensions.codec.NiciraSetNshContextHeaderCodec; ...@@ -39,6 +41,8 @@ import org.onosproject.driver.extensions.codec.NiciraSetNshContextHeaderCodec;
39 import org.onosproject.driver.extensions.codec.NiciraSetNshSiCodec; 41 import org.onosproject.driver.extensions.codec.NiciraSetNshSiCodec;
40 import org.onosproject.driver.extensions.codec.NiciraSetNshSpiCodec; 42 import org.onosproject.driver.extensions.codec.NiciraSetNshSpiCodec;
41 import org.onosproject.driver.extensions.codec.NiciraSetTunnelDstCodec; 43 import org.onosproject.driver.extensions.codec.NiciraSetTunnelDstCodec;
44 +import org.onosproject.driver.extensions.codec.OfdpaMatchVlanVidCodec;
45 +import org.onosproject.driver.extensions.codec.OfdpaSetVlanVidCodec;
42 import org.slf4j.Logger; 46 import org.slf4j.Logger;
43 47
44 import static org.slf4j.LoggerFactory.getLogger; 48 import static org.slf4j.LoggerFactory.getLogger;
...@@ -65,6 +69,8 @@ public class DefaultCodecRegister { ...@@ -65,6 +69,8 @@ public class DefaultCodecRegister {
65 codecService.registerCodec(NiciraSetNshSpi.class, new NiciraSetNshSpiCodec()); 69 codecService.registerCodec(NiciraSetNshSpi.class, new NiciraSetNshSpiCodec());
66 codecService.registerCodec(NiciraSetTunnelDst.class, new NiciraSetTunnelDstCodec()); 70 codecService.registerCodec(NiciraSetTunnelDst.class, new NiciraSetTunnelDstCodec());
67 codecService.registerCodec(NiciraSetNshContextHeader.class, new NiciraSetNshContextHeaderCodec()); 71 codecService.registerCodec(NiciraSetNshContextHeader.class, new NiciraSetNshContextHeaderCodec());
72 + codecService.registerCodec(OfdpaMatchVlanVid.class, new OfdpaMatchVlanVidCodec());
73 + codecService.registerCodec(OfdpaSetVlanVid.class, new OfdpaSetVlanVidCodec());
68 log.info("Registered default driver codecs."); 74 log.info("Registered default driver codecs.");
69 } 75 }
70 76
...@@ -79,6 +85,8 @@ public class DefaultCodecRegister { ...@@ -79,6 +85,8 @@ public class DefaultCodecRegister {
79 codecService.unregisterCodec(NiciraSetNshSpi.class); 85 codecService.unregisterCodec(NiciraSetNshSpi.class);
80 codecService.unregisterCodec(NiciraSetTunnelDst.class); 86 codecService.unregisterCodec(NiciraSetTunnelDst.class);
81 codecService.unregisterCodec(NiciraSetNshContextHeader.class); 87 codecService.unregisterCodec(NiciraSetNshContextHeader.class);
88 + codecService.unregisterCodec(OfdpaMatchVlanVid.class);
89 + codecService.unregisterCodec(OfdpaSetVlanVid.class);
82 log.info("Unregistered default driver codecs."); 90 log.info("Unregistered default driver codecs.");
83 } 91 }
84 } 92 }
......
...@@ -76,9 +76,6 @@ public final class MoveExtensionTreatmentCodec extends JsonCodec<MoveExtensionTr ...@@ -76,9 +76,6 @@ public final class MoveExtensionTreatmentCodec extends JsonCodec<MoveExtensionTr
76 // parse dst 76 // parse dst
77 int dst = nullIsIllegal(json.get(DST), DST + MISSING_MEMBER_MESSAGE).asInt(); 77 int dst = nullIsIllegal(json.get(DST), DST + MISSING_MEMBER_MESSAGE).asInt();
78 78
79 - MoveExtensionTreatment moveExtensionTreatment = 79 + return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, src, dst, type);
80 - new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, src, dst, type);
81 -
82 - return moveExtensionTreatment;
83 } 80 }
84 } 81 }
......
...@@ -52,8 +52,6 @@ public final class NiciraMatchNshSiCodec extends JsonCodec<NiciraMatchNshSi> { ...@@ -52,8 +52,6 @@ public final class NiciraMatchNshSiCodec extends JsonCodec<NiciraMatchNshSi> {
52 NSH_SERVICE_INDEX + MISSING_MEMBER_MESSAGE).asInt(); 52 NSH_SERVICE_INDEX + MISSING_MEMBER_MESSAGE).asInt();
53 NshServiceIndex nshSi = NshServiceIndex.of(nshSiShort); 53 NshServiceIndex nshSi = NshServiceIndex.of(nshSiShort);
54 54
55 - NiciraMatchNshSi niciraMatchNshSi = new NiciraMatchNshSi(nshSi); 55 + return new NiciraMatchNshSi(nshSi);
56 -
57 - return niciraMatchNshSi;
58 } 56 }
59 } 57 }
......
...@@ -52,8 +52,6 @@ public final class NiciraMatchNshSpiCodec extends JsonCodec<NiciraMatchNshSpi> { ...@@ -52,8 +52,6 @@ public final class NiciraMatchNshSpiCodec extends JsonCodec<NiciraMatchNshSpi> {
52 NSH_PATH_ID + MISSING_MEMBER_MESSAGE).asInt(); 52 NSH_PATH_ID + MISSING_MEMBER_MESSAGE).asInt();
53 NshServicePathId nshSpi = NshServicePathId.of(nshSpiInt); 53 NshServicePathId nshSpi = NshServicePathId.of(nshSpiInt);
54 54
55 - NiciraMatchNshSpi niciraMatchNshSpi = new NiciraMatchNshSpi(nshSpi); 55 + return new NiciraMatchNshSpi(nshSpi);
56 -
57 - return niciraMatchNshSpi;
58 } 56 }
59 } 57 }
......
...@@ -53,8 +53,6 @@ public final class NiciraResubmitCodec extends JsonCodec<NiciraResubmit> { ...@@ -53,8 +53,6 @@ public final class NiciraResubmitCodec extends JsonCodec<NiciraResubmit> {
53 long portNumberLong = nullIsIllegal(json.get(RESUBMIT_PORT), RESUBMIT_PORT + MISSING_MEMBER_MESSAGE).asLong(); 53 long portNumberLong = nullIsIllegal(json.get(RESUBMIT_PORT), RESUBMIT_PORT + MISSING_MEMBER_MESSAGE).asLong();
54 PortNumber portNumber = PortNumber.portNumber(portNumberLong); 54 PortNumber portNumber = PortNumber.portNumber(portNumberLong);
55 55
56 - NiciraResubmit niciraResubmit = new NiciraResubmit(portNumber); 56 + return new NiciraResubmit(portNumber);
57 -
58 - return niciraResubmit;
59 } 57 }
60 } 58 }
......
...@@ -58,8 +58,6 @@ public final class NiciraResubmitTableCodec extends JsonCodec<NiciraResubmitTabl ...@@ -58,8 +58,6 @@ public final class NiciraResubmitTableCodec extends JsonCodec<NiciraResubmitTabl
58 short tableId = (short) nullIsIllegal(json.get(RESUBMIT_TABLE), 58 short tableId = (short) nullIsIllegal(json.get(RESUBMIT_TABLE),
59 RESUBMIT_TABLE + MISSING_MEMBER_MESSAGE).asInt(); 59 RESUBMIT_TABLE + MISSING_MEMBER_MESSAGE).asInt();
60 60
61 - NiciraResubmitTable niciraResubmitTable = new NiciraResubmitTable(portNumber, tableId); 61 + return new NiciraResubmitTable(portNumber, tableId);
62 -
63 - return niciraResubmitTable;
64 } 62 }
65 } 63 }
......
...@@ -62,9 +62,6 @@ public class NiciraSetNshContextHeaderCodec extends JsonCodec<NiciraSetNshContex ...@@ -62,9 +62,6 @@ public class NiciraSetNshContextHeaderCodec extends JsonCodec<NiciraSetNshContex
62 62
63 ExtensionTreatmentType type = new ExtensionTreatmentType(extensionTypeInt); 63 ExtensionTreatmentType type = new ExtensionTreatmentType(extensionTypeInt);
64 64
65 - NiciraSetNshContextHeader niciraSetNshContextHeader = 65 + return new NiciraSetNshContextHeader(contextHeader, type);
66 - new NiciraSetNshContextHeader(contextHeader, type);
67 -
68 - return niciraSetNshContextHeader;
69 } 66 }
70 } 67 }
......
...@@ -53,8 +53,6 @@ public final class NiciraSetNshSiCodec extends JsonCodec<NiciraSetNshSi> { ...@@ -53,8 +53,6 @@ public final class NiciraSetNshSiCodec extends JsonCodec<NiciraSetNshSi> {
53 53
54 NshServiceIndex index = NshServiceIndex.of(serviceIndexShort); 54 NshServiceIndex index = NshServiceIndex.of(serviceIndexShort);
55 55
56 - NiciraSetNshSi niciraSetNshSi = new NiciraSetNshSi(index); 56 + return new NiciraSetNshSi(index);
57 -
58 - return niciraSetNshSi;
59 } 57 }
60 } 58 }
......
...@@ -53,8 +53,6 @@ public final class NiciraSetNshSpiCodec extends JsonCodec<NiciraSetNshSpi> { ...@@ -53,8 +53,6 @@ public final class NiciraSetNshSpiCodec extends JsonCodec<NiciraSetNshSpi> {
53 53
54 NshServicePathId pathId = NshServicePathId.of(servicePathIdInt); 54 NshServicePathId pathId = NshServicePathId.of(servicePathIdInt);
55 55
56 - NiciraSetNshSpi niciraSetNshSpi = new NiciraSetNshSpi(pathId); 56 + return new NiciraSetNshSpi(pathId);
57 -
58 - return niciraSetNshSpi;
59 } 57 }
60 } 58 }
......
...@@ -52,8 +52,6 @@ public final class NiciraSetTunnelDstCodec extends JsonCodec<NiciraSetTunnelDst> ...@@ -52,8 +52,6 @@ public final class NiciraSetTunnelDstCodec extends JsonCodec<NiciraSetTunnelDst>
52 52
53 Ip4Address tunnelDst = Ip4Address.valueOf(dstIp); 53 Ip4Address tunnelDst = Ip4Address.valueOf(dstIp);
54 54
55 - NiciraSetTunnelDst niciraSetTunnelDst = new NiciraSetTunnelDst(tunnelDst); 55 + return new NiciraSetTunnelDst(tunnelDst);
56 -
57 - return niciraSetTunnelDst;
58 } 56 }
59 } 57 }
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.driver.extensions.codec;
17 +
18 +import com.fasterxml.jackson.databind.node.ObjectNode;
19 +import org.onlab.packet.VlanId;
20 +import org.onosproject.codec.CodecContext;
21 +import org.onosproject.codec.JsonCodec;
22 +import org.onosproject.driver.extensions.OfdpaMatchVlanVid;
23 +
24 +import static com.google.common.base.Preconditions.checkNotNull;
25 +import static org.onlab.util.Tools.nullIsIllegal;
26 +
27 +/**
28 + * JSON Codec for Ofdpa match vlan vid class.
29 + */
30 +public class OfdpaMatchVlanVidCodec extends JsonCodec<OfdpaMatchVlanVid> {
31 +
32 + private static final String VLAN_ID = "vlanId";
33 +
34 + private static final String MISSING_MEMBER_MESSAGE = " member is required in OfdpaMatchVlanVid";
35 +
36 + @Override
37 + public ObjectNode encode(OfdpaMatchVlanVid vlanId, CodecContext context) {
38 + checkNotNull(vlanId, "Vlan ID cannot be null");
39 + ObjectNode root = context.mapper().createObjectNode()
40 + .put(VLAN_ID, vlanId.vlanId().id());
41 + return root;
42 + }
43 +
44 + @Override
45 + public OfdpaMatchVlanVid decode(ObjectNode json, CodecContext context) {
46 + if (json == null || !json.isObject()) {
47 + return null;
48 + }
49 +
50 + // parse ofdpa match vlan vid
51 + short vlanVid = (short) nullIsIllegal(json.get(VLAN_ID),
52 + VLAN_ID + MISSING_MEMBER_MESSAGE).asInt();
53 + return new OfdpaMatchVlanVid(VlanId.vlanId(vlanVid));
54 + }
55 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.driver.extensions.codec;
17 +
18 +import com.fasterxml.jackson.databind.node.ObjectNode;
19 +import org.onlab.packet.VlanId;
20 +import org.onosproject.codec.CodecContext;
21 +import org.onosproject.codec.JsonCodec;
22 +import org.onosproject.driver.extensions.OfdpaSetVlanVid;
23 +
24 +import static com.google.common.base.Preconditions.checkNotNull;
25 +import static org.onlab.util.Tools.nullIsIllegal;
26 +
27 +/**
28 + * JSON Codec for Ofdpa set vlan vid class.
29 + */
30 +public class OfdpaSetVlanVidCodec extends JsonCodec<OfdpaSetVlanVid> {
31 +
32 + private static final String VLAN_ID = "vlanId";
33 +
34 + private static final String MISSING_MEMBER_MESSAGE = " member is required in OfdpaSetVlanVid";
35 +
36 + @Override
37 + public ObjectNode encode(OfdpaSetVlanVid vlanId, CodecContext context) {
38 + checkNotNull(vlanId, "Vlan ID cannot be null");
39 + ObjectNode root = context.mapper().createObjectNode()
40 + .put(VLAN_ID, vlanId.vlanId().id());
41 + return root;
42 + }
43 +
44 + @Override
45 + public OfdpaSetVlanVid decode(ObjectNode json, CodecContext context) {
46 + if (json == null || !json.isObject()) {
47 + return null;
48 + }
49 +
50 + // parse ofdpa set vlan vid
51 + short vlanVid = (short) nullIsIllegal(json.get(VLAN_ID),
52 + VLAN_ID + MISSING_MEMBER_MESSAGE).asInt();
53 + return new OfdpaSetVlanVid(VlanId.vlanId(vlanVid));
54 + }
55 +}