use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort in project onos by opennetworkinglab.
the class MepWebResource method transmitLinktrace.
/**
* Transmit Linktrace on MEP with MD name, MA name and Mep Id.
*
* @onos.rsModel MepLtTransmit
* @param mdName The name of a Maintenance Domain
* @param maName The name of a Maintenance Association belonging to the MD
* @param mepIdShort The id of a MEP belonging to the MA
* @param input A JSON formatted input stream specifying the Linktrace parameters
* @return 202 Received with success message or 500 on error
*/
@PUT
@Path("{mep_id}/transmit-linktrace")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response transmitLinktrace(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepIdShort, InputStream input) {
log.debug("PUT called to Transmit Linktrace on Mep");
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MaintenanceDomain md;
Optional<MaintenanceDomain> mdOpt = get(CfmMdService.class).getMaintenanceDomain(mdId);
if (mdOpt.isPresent()) {
md = mdOpt.get();
} else {
return Response.serverError().entity("{ \"failure\":\"" + mdName + " does not exist\" }").build();
}
MaintenanceAssociation ma;
Optional<MaintenanceAssociation> maOpt = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId);
if (maOpt.isPresent()) {
ma = maOpt.get();
} else {
return Response.serverError().entity("{ \"failure\":\"" + maName + " does not exist\" }").build();
}
MepId mepId = MepId.valueOf(mepIdShort);
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode cfg = readTreeFromStream(mapper, input);
JsonCodec<MepLtCreate> mepLtCreateCodec = codec(MepLtCreate.class);
MepLtCreate ltCreate = mepLtCreateCodec.decode((ObjectNode) cfg, this);
get(CfmMepService.class).transmitLinktrace(md.mdId(), ma.maId(), mepId, ltCreate);
} catch (Exception | CfmConfigException e) {
log.error("Transmit Linktrace on " + mdName + "/" + maName + "/{} failed", String.valueOf(mepIdShort), e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
return Response.accepted().entity("{ \"success\":\"Linktrace on MEP " + mdName + "/" + ma.maId() + "/" + mepId.id() + " started\" }").build();
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort in project onos by opennetworkinglab.
the class MepWebResource method getMep.
/**
* Get MEP by MD name, MA name and Mep Id.
*
* @param mdName The name of a Maintenance Domain
* @param maName The name of a Maintenance Association belonging to the MD
* @param mepId The Id of the MEP
* @return 200 OK with details of the MEP or 500 on error
*/
@GET
@Path("{mep_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, @PathParam("mep_id") short mepId) {
log.debug("GET called for MEP {}", mdName + "/" + maName + "/" + mepId);
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MepEntry mepEntry = get(CfmMepService.class).getMep(mdId, maId, MepId.valueOf(mepId));
if (mepEntry == null) {
return Response.serverError().entity("{ \"failure\":\"MEP " + mdName + "/" + maName + "/" + mepId + " not found\" }").build();
}
ObjectNode node = mapper().createObjectNode();
node.set("mep", codec(MepEntry.class).encode(mepEntry, this));
return ok(node).build();
} catch (CfmConfigException e) {
log.error("Get Mep {} failed because of exception", mdName + "/" + maName + "/" + mepId, e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort in project onos by opennetworkinglab.
the class MepWebResource method createMep.
/**
* Create MEP with MD name, MA name and Mep Json.
*
* @onos.rsModel MepCreate
* @param mdName The name of a Maintenance Domain
* @param maName The name of a Maintenance Association belonging to the MD
* @param input A JSON formatted input stream specifying the Mep parameters
* @return 201 Created or 304 if already exists or 500 on error
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createMep(@PathParam("md_name") String mdName, @PathParam("ma_name") String maName, InputStream input) {
log.debug("POST called to Create Mep");
try {
MdId mdId = MdIdCharStr.asMdId(mdName);
MaIdShort maId = MaIdCharStr.asMaId(maName);
MaintenanceAssociation ma = get(CfmMdService.class).getMaintenanceAssociation(mdId, maId).orElseThrow(() -> new IllegalArgumentException("MA " + mdName + "/" + maName + " not Found"));
ObjectMapper mapper = new ObjectMapper();
JsonNode cfg = readTreeFromStream(mapper(), input);
JsonCodec<Mep> mepCodec = codec(Mep.class);
Mep mep = ((MepCodec) mepCodec).decode((ObjectNode) cfg, this, mdName, maName);
Boolean didNotExist = get(CfmMepService.class).createMep(mdId, maId, mep);
if (!didNotExist) {
return Response.notModified(mdName + "/" + ma.maId() + "/" + mep.mepId() + " already exists").build();
}
return Response.created(new URI("md/" + mdName + "/ma/" + ma.maId() + "/mep/" + mep.mepId())).entity("{ \"success\":\"mep " + mdName + "/" + ma.maId() + "/" + mep.mepId() + " created\" }").build();
} catch (Exception | CfmConfigException e) {
log.error("Create Mep on " + mdName + "/" + maName + " failed because of exception {}", e);
return Response.serverError().entity("{ \"failure\":\"" + e.toString() + "\" }").build();
}
}
use of org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort 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.MaIdShort 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