use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId 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);
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId in project onos by opennetworkinglab.
the class MepLtCreateCodec method decode.
/**
* Decodes the MepLtCreate entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @return decoded MepLtCreate
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
@Override
public MepLtCreate decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode linktraceNode = json.get(LINKTRACE);
JsonNode remoteMepIdNode = linktraceNode.get(REMOTE_MEP_ID);
JsonNode remoteMepMacNode = linktraceNode.get(REMOTE_MEP_MAC);
MepLtCreate.MepLtCreateBuilder ltCreateBuilder;
if (remoteMepIdNode != null) {
MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
ltCreateBuilder = DefaultMepLtCreate.builder(remoteMepId);
} else if (remoteMepMacNode != null) {
MacAddress remoteMepMac = MacAddress.valueOf(remoteMepMacNode.asText());
ltCreateBuilder = DefaultMepLtCreate.builder(remoteMepMac);
} else {
throw new IllegalArgumentException("Either a remoteMepId or a remoteMepMac");
}
JsonNode defaultTtlNode = linktraceNode.get(DEFAULT_TTL);
if (defaultTtlNode != null) {
short defaultTtl = (short) defaultTtlNode.asInt();
ltCreateBuilder.defaultTtl(defaultTtl);
}
JsonNode transmitLtmFlagsNode = linktraceNode.get(TRANSMIT_LTM_FLAGS);
if (transmitLtmFlagsNode != null) {
if (transmitLtmFlagsNode.asText().isEmpty()) {
ltCreateBuilder.transmitLtmFlags(BitSet.valueOf(new long[] { 0 }));
} else if (transmitLtmFlagsNode.asText().equals(USE_FDB_ONLY)) {
ltCreateBuilder.transmitLtmFlags(BitSet.valueOf(new long[] { 1 }));
} else {
throw new IllegalArgumentException("Expecting value 'use-fdb-only' " + "or '' for " + TRANSMIT_LTM_FLAGS);
}
}
return ltCreateBuilder.build();
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId in project onos by opennetworkinglab.
the class CfmMepListCommand method doExecute.
@Override
protected void doExecute() {
CfmMepService mepService = get(CfmMepService.class);
CfmMdService mdService = get(CfmMdService.class);
if (mdStr != null && !mdStr.isEmpty()) {
MdId mdId = parseMdName(mdStr);
print(printMdId(mdId));
if (maStr != null && !maStr.isEmpty()) {
MaIdShort maId = parseMaName(maStr);
print(printMaId(maId));
if (mepStr != null && !mepStr.isEmpty()) {
MepId mepId = MepId.valueOf(Short.parseShort(mepStr));
try {
MepEntry mep = mepService.getMep(mdId, maId, mepId);
if (mep != null) {
print(printMepEntry(mep));
}
} catch (CfmConfigException e) {
log.error("Error retrieving Mep details {}", new MepKeyId(mdId, maId, mepId), e);
}
// MD, MA and MEP given
} else {
// MD and MA given but no MEP given
try {
mepService.getAllMeps(mdId, maId).forEach(mep -> print(printMepEntry(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for {}/{}", mdId.mdName(), maId.maName(), e);
}
}
} else {
// MD given but no MA given
mdService.getAllMaintenanceAssociation(mdId).forEach(ma -> {
print(printMaId(ma.maId()));
try {
mepService.getAllMeps(mdId, ma.maId()).forEach(mep -> print(printMepEntry(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for {}/{}", mdId.mdName(), ma.maId().maName(), e);
}
});
}
} else {
mdService.getAllMaintenanceDomain().forEach(md -> {
print(printMdId(md.mdId()));
mdService.getAllMaintenanceAssociation(md.mdId()).forEach(ma -> {
print(printMaId(ma.maId()));
try {
mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep -> print(printMepEntry(mep)));
} catch (CfmConfigException e) {
log.error("Error retrieving Meps for {}/{}", md.mdId().mdName(), ma.maId().maName(), e);
}
});
});
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId in project onos by opennetworkinglab.
the class MepWebResourceTest method testCreateMep.
@Test
public void testCreateMep() throws CfmConfigException, IOException {
MepId mepId2 = MepId.valueOf((short) 2);
Mep mep2 = DefaultMep.builder(mepId2, DeviceId.deviceId("netconf:2.2.3.4:830"), PortNumber.portNumber(2), Mep.MepDirection.UP_MEP, MDNAME1, MANAME1).build();
MaintenanceAssociation ma1 = DefaultMaintenanceAssociation.builder(MANAME1, MDNAME1.getNameLength()).build();
expect(mdService.getMaintenanceAssociation(MDNAME1, MANAME1)).andReturn(Optional.ofNullable(ma1)).anyTimes();
replay(mdService);
expect(mepService.createMep(MDNAME1, MANAME1, mep2)).andReturn(true).anyTimes();
replay(mepService);
ObjectMapper mapper = new ObjectMapper();
CfmCodecContext context = new CfmCodecContext();
ObjectNode node = mapper.createObjectNode();
node.set("mep", context.codec(Mep.class).encode(mep2, context));
final WebTarget wt = target();
final Response response = wt.path("md/" + MDNAME1.mdName() + "/ma/" + MANAME1.maName() + "/mep").request().post(Entity.json(node.toString()));
assertEquals("Expecting 201", 201, response.getStatus());
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MepId in project onos by opennetworkinglab.
the class LmCreateCodec method decode.
@Override
public LossMeasurementCreate decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode lmNode = json.get(LM);
Version version = Version.Y17312011;
if (lmNode.get(VERSION) != null) {
version = Version.valueOf(lmNode.get(VERSION).asText());
}
LmType lmCfgType = LmType.LMLMM;
if (lmNode.get(LM_CFG_TYPE) != null) {
lmCfgType = LmType.valueOf(lmNode.get(LM_CFG_TYPE).asText(LMLMM));
}
MepId remoteMepId = MepId.valueOf(nullIsIllegal(lmNode.get(REMOTE_MEP_ID), REMOTE_MEP_ID + " is required").shortValue());
Priority prio = Priority.valueOf(nullIsIllegal(lmNode.get(PRIORITY), PRIORITY + " is required in the format 'PRIOn'").asText());
try {
LmCreateBuilder builder = DefaultLmCreate.builder(version, remoteMepId, prio, lmCfgType);
if (lmNode.get(COUNTERS_ENABLED) != null) {
context.codec(CounterOption.class).decode((ArrayNode) (lmNode.get(COUNTERS_ENABLED)), context).forEach(builder::addToCountersEnabled);
}
if (lmNode.get(THRESHOLDS) != null) {
context.codec(LossMeasurementThreshold.class).decode((ArrayNode) (lmNode.get(THRESHOLDS)), context).forEach(builder::addToLossMeasurementThreshold);
}
if (lmNode.get(AVAILABILITY_MEASUREMENT_INTERVAL_MINS) != null) {
builder = builder.availabilityMeasurementInterval(Duration.ofMinutes(lmNode.get(AVAILABILITY_MEASUREMENT_INTERVAL_MINS).asInt()));
}
if (lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_FLR_MEASUREMENTS) != null) {
builder = builder.availabilityNumberConsecutiveFlrMeasurements(lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_FLR_MEASUREMENTS).asInt());
}
if (lmNode.get(AVAILABILITY_FLR_THRESHOLD_PCT) != null) {
builder = builder.availabilityFlrThreshold(MilliPct.ofPercent((float) lmNode.get(AVAILABILITY_FLR_THRESHOLD_PCT).asDouble()));
}
if (lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_INTERVALS) != null) {
builder = builder.availabilityNumberConsecutiveIntervals((short) lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_INTERVALS).asInt());
}
if (lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_HIGH_FLR) != null) {
builder = builder.availabilityNumberConsecutiveHighFlr((short) lmNode.get(AVAILABILITY_NUMBER_CONSECUTIVE_HIGH_FLR).asInt());
}
if (lmNode.get(FRAME_SIZE) != null) {
builder = (LmCreateBuilder) builder.frameSize((short) lmNode.get(FRAME_SIZE).asInt());
}
if (lmNode.get(MESSAGE_PERIOD_MS) != null) {
builder = (LmCreateBuilder) builder.messagePeriod(Duration.ofMillis(lmNode.get(MESSAGE_PERIOD_MS).asInt()));
}
if (lmNode.get(MEASUREMENT_INTERVAL_MINS) != null) {
builder = (LmCreateBuilder) builder.measurementInterval(Duration.ofMinutes(lmNode.get(MEASUREMENT_INTERVAL_MINS).asInt()));
}
if (lmNode.get(ALIGN_MEASUREMENT_INTERVALS) != null) {
builder = (LmCreateBuilder) builder.alignMeasurementIntervals(lmNode.get(ALIGN_MEASUREMENT_INTERVALS).asBoolean());
}
if (lmNode.get(ALIGN_MEASUREMENT_OFFSET_MINS) != null) {
builder = (LmCreateBuilder) builder.alignMeasurementOffset(Duration.ofMinutes(lmNode.get(ALIGN_MEASUREMENT_OFFSET_MINS).asInt()));
}
if (lmNode.get(START_TIME) != null) {
builder = (LmCreateBuilder) builder.startTime(context.codec(StartTime.class).decode((ObjectNode) lmNode.get(START_TIME), context));
}
if (lmNode.get(STOP_TIME) != null) {
builder = (LmCreateBuilder) builder.stopTime(context.codec(StopTime.class).decode((ObjectNode) lmNode.get(STOP_TIME), context));
}
return builder.build();
} catch (SoamConfigException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations