use of org.onosproject.incubator.net.l2monitoring.cfm.Component in project onos by opennetworkinglab.
the class ComponentCodec method decode.
/**
* Decodes the Component entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @return decoded Component
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
@Override
public Component decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode componentNode = json.get(COMPONENT);
int componentId = nullIsIllegal(componentNode.get(COMPONENT_ID), "component-id is required").asInt();
Component.ComponentBuilder componentBuilder = DefaultComponent.builder(componentId);
List<VlanId> vidList = (new VidCodec()).decode((ArrayNode) nullIsIllegal(componentNode.get(VID_LIST), "vid-list is required"), context);
if (vidList == null || vidList.isEmpty()) {
throw new IllegalArgumentException("A least one VID is required in component: " + componentId);
}
for (VlanId vid : vidList) {
componentBuilder = componentBuilder.addToVidList(vid);
}
if (componentNode.get(TAG_TYPE) != null) {
componentBuilder = componentBuilder.tagType(Component.TagType.valueOf(componentNode.get(TAG_TYPE).asText()));
}
if (componentNode.get(MHF_CREATION_TYPE) != null) {
componentBuilder = componentBuilder.mhfCreationType(Component.MhfCreationType.valueOf(componentNode.get(MHF_CREATION_TYPE).asText()));
}
if (componentNode.get(ID_PERMISSION) != null) {
componentBuilder = componentBuilder.idPermission(Component.IdPermissionType.valueOf(componentNode.get(ID_PERMISSION).asText()));
}
return componentBuilder.build();
}
use of org.onosproject.incubator.net.l2monitoring.cfm.Component in project onos by opennetworkinglab.
the class MaintenanceAssociationCodec method decode.
/**
* Decodes the MaintenanceAssociation entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @param mdNameLen the length of the corresponding MD's name
* @return decoded MaintenanceAssociation
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
public MaintenanceAssociation decode(ObjectNode json, CodecContext context, int mdNameLen) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode maNode = json.get(MA);
String maName = nullIsIllegal(maNode.get(MA_NAME), "maName is required").asText();
String maNameType = MaIdShort.MaIdType.CHARACTERSTRING.name();
if (maNode.get(MA_NAME_TYPE) != null) {
maNameType = maNode.get(MA_NAME_TYPE).asText();
}
try {
MaIdShort maId = MdMaNameUtil.parseMaName(maNameType, maName);
MaBuilder builder = DefaultMaintenanceAssociation.builder(maId, mdNameLen);
JsonNode maNumericIdNode = maNode.get(MA_NUMERIC_ID);
if (maNumericIdNode != null) {
short mdNumericId = (short) maNumericIdNode.asInt();
builder = builder.maNumericId(mdNumericId);
}
if (maNode.get(CCM_INTERVAL) != null) {
builder.ccmInterval(CcmInterval.valueOf(maNode.get(CCM_INTERVAL).asText()));
}
List<Component> componentList = (new ComponentCodec()).decode((ArrayNode) nullIsIllegal(maNode.get(COMPONENT_LIST), "component-list is required"), context);
for (Component component : componentList) {
builder = builder.addToComponentList(component);
}
JsonNode rmepListJson = maNode.get(RMEP_LIST);
if (rmepListJson != null) {
List<MepId> remoteMeps = (new RMepCodec()).decode((ArrayNode) rmepListJson, context);
for (MepId remoteMep : remoteMeps) {
builder = builder.addToRemoteMepIdList(remoteMep);
}
}
return builder.build();
} catch (CfmConfigException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations