use of org.onosproject.incubator.net.l2monitoring.cfm.Mep.MepDirection in project onos by opennetworkinglab.
the class MepCodec method decode.
/**
* Decodes the Mep entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @param mdName The MD name
* @param maName The MA name
* @return decoded Mep
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
public Mep decode(ObjectNode json, CodecContext context, String mdName, String maName) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode mepNode = json.get("mep");
int mepId = Integer.parseInt(nullIsIllegal(mepNode.get("mepId"), "mepId is required").asText());
DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(mepNode.get("deviceId"), "deviceId is required").asText());
PortNumber port = PortNumber.portNumber(Long.parseLong(nullIsIllegal(mepNode.get("port"), "port is required").asText()));
MepDirection direction = MepDirection.valueOf(nullIsIllegal(mepNode.get("direction"), "direction is required").asText());
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MepBuilder mepBuilder = DefaultMep.builder(MepId.valueOf((short) mepId), deviceId, port, direction, mdId, maId);
if (mepNode.get(PRIMARY_VID) != null) {
mepBuilder.primaryVid(VlanId.vlanId((short) mepNode.get(PRIMARY_VID).asInt(0)));
}
if (mepNode.get(ADMINISTRATIVE_STATE) != null) {
mepBuilder.administrativeState(mepNode.get(ADMINISTRATIVE_STATE).asBoolean());
}
if (mepNode.get(CCM_LTM_PRIORITY) != null) {
mepBuilder.ccmLtmPriority(Priority.values()[mepNode.get(CCM_LTM_PRIORITY).asInt(0)]);
}
if (mepNode.get(CCI_ENABLED) != null) {
mepBuilder.cciEnabled(mepNode.get(CCI_ENABLED).asBoolean());
}
if (mepNode.get(LOWEST_FAULT_PRIORITY_DEFECT) != null) {
mepBuilder.lowestFaultPriorityDefect(Mep.LowestFaultDefect.values()[mepNode.get(LOWEST_FAULT_PRIORITY_DEFECT).asInt()]);
}
if (mepNode.get(DEFECT_ABSENT_TIME) != null) {
mepBuilder.defectAbsentTime(Duration.parse(mepNode.get(DEFECT_ABSENT_TIME).asText()));
}
if (mepNode.get(DEFECT_PRESENT_TIME) != null) {
mepBuilder.defectPresentTime(Duration.parse(mepNode.get(DEFECT_PRESENT_TIME).asText()));
}
if (mepNode.get(FNG_ADDRESS) != null) {
mepBuilder.fngAddress((new FngAddressCodec()).decode((ObjectNode) mepNode, context));
}
return mepBuilder.build();
} catch (CfmConfigException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations