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;
import org.onosproject.driver.extensions.NiciraSetNshSi;
import org.onosproject.driver.extensions.NiciraSetNshSpi;
import org.onosproject.driver.extensions.NiciraSetTunnelDst;
import org.onosproject.driver.extensions.OfdpaMatchVlanVid;
import org.onosproject.driver.extensions.OfdpaSetVlanVid;
import org.onosproject.driver.extensions.codec.MoveExtensionTreatmentCodec;
import org.onosproject.driver.extensions.codec.NiciraMatchNshSiCodec;
import org.onosproject.driver.extensions.codec.NiciraMatchNshSpiCodec;
......@@ -39,6 +41,8 @@ import org.onosproject.driver.extensions.codec.NiciraSetNshContextHeaderCodec;
import org.onosproject.driver.extensions.codec.NiciraSetNshSiCodec;
import org.onosproject.driver.extensions.codec.NiciraSetNshSpiCodec;
import org.onosproject.driver.extensions.codec.NiciraSetTunnelDstCodec;
import org.onosproject.driver.extensions.codec.OfdpaMatchVlanVidCodec;
import org.onosproject.driver.extensions.codec.OfdpaSetVlanVidCodec;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -65,6 +69,8 @@ public class DefaultCodecRegister {
codecService.registerCodec(NiciraSetNshSpi.class, new NiciraSetNshSpiCodec());
codecService.registerCodec(NiciraSetTunnelDst.class, new NiciraSetTunnelDstCodec());
codecService.registerCodec(NiciraSetNshContextHeader.class, new NiciraSetNshContextHeaderCodec());
codecService.registerCodec(OfdpaMatchVlanVid.class, new OfdpaMatchVlanVidCodec());
codecService.registerCodec(OfdpaSetVlanVid.class, new OfdpaSetVlanVidCodec());
log.info("Registered default driver codecs.");
}
......@@ -79,6 +85,8 @@ public class DefaultCodecRegister {
codecService.unregisterCodec(NiciraSetNshSpi.class);
codecService.unregisterCodec(NiciraSetTunnelDst.class);
codecService.unregisterCodec(NiciraSetNshContextHeader.class);
codecService.unregisterCodec(OfdpaMatchVlanVid.class);
codecService.unregisterCodec(OfdpaSetVlanVid.class);
log.info("Unregistered default driver codecs.");
}
}
......
......@@ -76,9 +76,6 @@ public final class MoveExtensionTreatmentCodec extends JsonCodec<MoveExtensionTr
// parse dst
int dst = nullIsIllegal(json.get(DST), DST + MISSING_MEMBER_MESSAGE).asInt();
MoveExtensionTreatment moveExtensionTreatment =
new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, src, dst, type);
return moveExtensionTreatment;
return new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, src, dst, type);
}
}
......
......@@ -52,8 +52,6 @@ public final class NiciraMatchNshSiCodec extends JsonCodec<NiciraMatchNshSi> {
NSH_SERVICE_INDEX + MISSING_MEMBER_MESSAGE).asInt();
NshServiceIndex nshSi = NshServiceIndex.of(nshSiShort);
NiciraMatchNshSi niciraMatchNshSi = new NiciraMatchNshSi(nshSi);
return niciraMatchNshSi;
return new NiciraMatchNshSi(nshSi);
}
}
......
......@@ -52,8 +52,6 @@ public final class NiciraMatchNshSpiCodec extends JsonCodec<NiciraMatchNshSpi> {
NSH_PATH_ID + MISSING_MEMBER_MESSAGE).asInt();
NshServicePathId nshSpi = NshServicePathId.of(nshSpiInt);
NiciraMatchNshSpi niciraMatchNshSpi = new NiciraMatchNshSpi(nshSpi);
return niciraMatchNshSpi;
return new NiciraMatchNshSpi(nshSpi);
}
}
......
......@@ -53,8 +53,6 @@ public final class NiciraResubmitCodec extends JsonCodec<NiciraResubmit> {
long portNumberLong = nullIsIllegal(json.get(RESUBMIT_PORT), RESUBMIT_PORT + MISSING_MEMBER_MESSAGE).asLong();
PortNumber portNumber = PortNumber.portNumber(portNumberLong);
NiciraResubmit niciraResubmit = new NiciraResubmit(portNumber);
return niciraResubmit;
return new NiciraResubmit(portNumber);
}
}
......
......@@ -58,8 +58,6 @@ public final class NiciraResubmitTableCodec extends JsonCodec<NiciraResubmitTabl
short tableId = (short) nullIsIllegal(json.get(RESUBMIT_TABLE),
RESUBMIT_TABLE + MISSING_MEMBER_MESSAGE).asInt();
NiciraResubmitTable niciraResubmitTable = new NiciraResubmitTable(portNumber, tableId);
return niciraResubmitTable;
return new NiciraResubmitTable(portNumber, tableId);
}
}
......
......@@ -62,9 +62,6 @@ public class NiciraSetNshContextHeaderCodec extends JsonCodec<NiciraSetNshContex
ExtensionTreatmentType type = new ExtensionTreatmentType(extensionTypeInt);
NiciraSetNshContextHeader niciraSetNshContextHeader =
new NiciraSetNshContextHeader(contextHeader, type);
return niciraSetNshContextHeader;
return new NiciraSetNshContextHeader(contextHeader, type);
}
}
......
......@@ -53,8 +53,6 @@ public final class NiciraSetNshSiCodec extends JsonCodec<NiciraSetNshSi> {
NshServiceIndex index = NshServiceIndex.of(serviceIndexShort);
NiciraSetNshSi niciraSetNshSi = new NiciraSetNshSi(index);
return niciraSetNshSi;
return new NiciraSetNshSi(index);
}
}
......
......@@ -53,8 +53,6 @@ public final class NiciraSetNshSpiCodec extends JsonCodec<NiciraSetNshSpi> {
NshServicePathId pathId = NshServicePathId.of(servicePathIdInt);
NiciraSetNshSpi niciraSetNshSpi = new NiciraSetNshSpi(pathId);
return niciraSetNshSpi;
return new NiciraSetNshSpi(pathId);
}
}
......
......@@ -52,8 +52,6 @@ public final class NiciraSetTunnelDstCodec extends JsonCodec<NiciraSetTunnelDst>
Ip4Address tunnelDst = Ip4Address.valueOf(dstIp);
NiciraSetTunnelDst niciraSetTunnelDst = new NiciraSetTunnelDst(tunnelDst);
return niciraSetTunnelDst;
return new NiciraSetTunnelDst(tunnelDst);
}
}
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.driver.extensions.codec;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.packet.VlanId;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.driver.extensions.OfdpaMatchVlanVid;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
/**
* JSON Codec for Ofdpa match vlan vid class.
*/
public class OfdpaMatchVlanVidCodec extends JsonCodec<OfdpaMatchVlanVid> {
private static final String VLAN_ID = "vlanId";
private static final String MISSING_MEMBER_MESSAGE = " member is required in OfdpaMatchVlanVid";
@Override
public ObjectNode encode(OfdpaMatchVlanVid vlanId, CodecContext context) {
checkNotNull(vlanId, "Vlan ID cannot be null");
ObjectNode root = context.mapper().createObjectNode()
.put(VLAN_ID, vlanId.vlanId().id());
return root;
}
@Override
public OfdpaMatchVlanVid decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
// parse ofdpa match vlan vid
short vlanVid = (short) nullIsIllegal(json.get(VLAN_ID),
VLAN_ID + MISSING_MEMBER_MESSAGE).asInt();
return new OfdpaMatchVlanVid(VlanId.vlanId(vlanVid));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.driver.extensions.codec;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.packet.VlanId;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.driver.extensions.OfdpaSetVlanVid;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
/**
* JSON Codec for Ofdpa set vlan vid class.
*/
public class OfdpaSetVlanVidCodec extends JsonCodec<OfdpaSetVlanVid> {
private static final String VLAN_ID = "vlanId";
private static final String MISSING_MEMBER_MESSAGE = " member is required in OfdpaSetVlanVid";
@Override
public ObjectNode encode(OfdpaSetVlanVid vlanId, CodecContext context) {
checkNotNull(vlanId, "Vlan ID cannot be null");
ObjectNode root = context.mapper().createObjectNode()
.put(VLAN_ID, vlanId.vlanId().id());
return root;
}
@Override
public OfdpaSetVlanVid decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
// parse ofdpa set vlan vid
short vlanVid = (short) nullIsIllegal(json.get(VLAN_ID),
VLAN_ID + MISSING_MEMBER_MESSAGE).asInt();
return new OfdpaSetVlanVid(VlanId.vlanId(vlanVid));
}
}