2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.lispflowmapping.northbound;
10 import java.util.List;
12 import javax.ws.rs.Consumes;
13 import javax.ws.rs.DELETE;
14 import javax.ws.rs.GET;
15 import javax.ws.rs.PUT;
16 import javax.ws.rs.Path;
17 import javax.ws.rs.PathParam;
18 import javax.ws.rs.Produces;
19 import javax.ws.rs.core.Context;
20 import javax.ws.rs.core.MediaType;
21 import javax.ws.rs.core.SecurityContext;
22 import javax.ws.rs.core.Response;
24 import org.codehaus.enunciate.jaxrs.ResponseCode;
25 import org.codehaus.enunciate.jaxrs.StatusCodes;
26 import org.codehaus.enunciate.jaxrs.TypeHint;
27 import org.opendaylight.controller.containermanager.IContainerManager;
28 import org.opendaylight.controller.northbound.commons.RestMessages;
29 import org.opendaylight.controller.northbound.commons.exception.BadRequestException;
30 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
31 import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
32 import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
33 import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException;
34 import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
35 import org.opendaylight.controller.sal.authorization.Privilege;
36 import org.opendaylight.controller.sal.utils.ServiceHelper;
37 import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
38 import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
39 import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
40 import org.opendaylight.lispflowmapping.type.lisp.EidRecord;
41 import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
42 import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
43 import org.opendaylight.lispflowmapping.type.lisp.MapRequest;
44 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
45 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddressGeneric;
46 import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
47 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapNotify;
48 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply;
49 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord;
50 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainer;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
55 public class LispMappingNorthbound implements ILispmappingNorthbound {
56 protected static final Logger logger = LoggerFactory.getLogger(LispMappingNorthbound.class);
57 private IFlowMapping mappingService;
59 private String userName;
61 // Based on code from controller project
63 public void setSecurityContext(SecurityContext context) {
64 if (context != null && context.getUserPrincipal() != null) {
65 userName = context.getUserPrincipal().getName();
69 protected String getUserName() {
73 public IFlowMapping getMappingService() {
74 return this.mappingService;
77 void setFlowMappingService(IFlowMapping mappingService) {
78 logger.trace("FlowMapping set in LispNorthbound");
79 this.mappingService = mappingService;
82 void unsetFlowMappingService(IFlowMapping mappingService) {
83 logger.trace("LispDAO was unset in LISP Northbound");
84 this.mappingService = null;
88 logger.trace("LISP Northbound Service is initialized!");
92 logger.info("LISP Northbound Service is up!");
96 logger.info("LISP Northbound Service is down!");
99 public void destroy() {
100 logger.trace("LISP Northbound Service is destroyed!");
101 mappingService = null;
104 // Based on code from controller project
105 private void handleContainerDoesNotExist(String containerName) {
106 IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(IContainerManager.class, this);
107 if (containerManager == null) {
108 throw new ServiceUnavailableException("Container " + containerName + RestMessages.NOCONTAINER.toString());
111 List<String> containerNames = containerManager.getContainerNames();
112 for (String cName : containerNames) {
113 if (cName.trim().equalsIgnoreCase(containerName.trim())) {
118 throw new ResourceNotFoundException("Container " + containerName + " " + RestMessages.NOCONTAINER.toString());
121 private void authorizationCheck(String containerName, Privilege privilege) {
123 if (!NorthboundUtils.isAuthorized(getUserName(), containerName, privilege, this)) {
124 throw new UnauthorizedException("User is not authorized to perform this operation on container " + containerName);
128 private EidToLocatorRecord lookupEID(String containerName, int mask, LispAddress EID) {
130 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
132 MapRequest mapRequest = new MapRequest();
133 EidRecord EIDRecord = new EidRecord((byte) mask, EID);
134 mapRequest.addEidRecord(EIDRecord);
135 mapRequest.setSourceEid(new LispIpv4Address("127.0.0.1"));
137 org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest mr = YangTransformerNB.transformMapRequest(mapRequest);
140 mapReply = nbService.getMappingService().handleMapRequest(mr);
141 } catch (Exception e) {
142 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error looking up the EID");
145 if (mapReply == null) {
146 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error looking up the EID");
149 EidToLocatorRecord record = null;
151 record = mapReply.getEidToLocatorRecord().get(0);
156 private void keyCheck(IFlowMapping mappingService, MapRegisterNB mapRegisterNB) {
158 String usedKey = mapRegisterNB.getKey();
160 LispAddressGeneric lispAddressGeneric;
161 LispAddress lispAddress;
165 int numEidRecords = mapRegisterNB.getMapRegister().getEidToLocatorRecords().size();
167 for (int i = 0; i < numEidRecords; i++) {
169 lispAddressGeneric = mapRegisterNB.getMapRegister().getEidToLocatorRecords().get(i).getPrefixGeneric();
172 lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
173 } catch (Exception e) {
174 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
176 mask = mapRegisterNB.getMapRegister().getEidToLocatorRecords().get(i).getMaskLength();
178 storedKey = mappingService.getAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress), mask);
179 } catch (Exception e) {
180 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while retrieving the key");
183 if (!usedKey.equals(storedKey)) {
184 throw new UnauthorizedException("The key used to register the mapping " + "does not match with the stored key for that mapping");
190 * Add a mapping to the LISP mapping system
192 * @param containerName
193 * name of the container context in which the mapping needs to be
195 * @param mapRegisterNB
196 * JSON object that contains the mapping information
198 * @return Text plain confirming reception
204 * http://localhost:8080/lispflowmapping/nb/v2/default/mapping
206 * Request body in JSON:
212 * "wantMapNotify" : true,
213 * "proxyMapReply" : false,
214 * "eidToLocatorRecords" :
217 * "authoritative" : true,
220 * "ipAddress" : "10.0.0.1",
225 * "action" : "NoAction",
229 * "multicastPriority" : 3,
232 * "ipAddress" : "3.3.3.3",
236 * "multicastWeight" : 3,
237 * "rlocProbed" : false,
238 * "localLocator" : false,
253 @Path("/{containerName}/mapping")
255 @Consumes(MediaType.APPLICATION_JSON)
256 @StatusCodes({ @ResponseCode(code = 400, condition = "Invalid data passed"),
257 @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
258 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
259 @ResponseCode(code = 500, condition = "Internal Server Error: Addition of mapping failed"),
260 @ResponseCode(code = 503, condition = "Service unavailable") })
261 public Response addMapping(@PathParam("containerName") String containerName, @TypeHint(MapRegisterNB.class) MapRegisterNB mapRegisterNB) {
263 handleContainerDoesNotExist(containerName);
265 authorizationCheck(containerName, Privilege.WRITE);
267 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
270 keyCheck(nbService.getMappingService(), mapRegisterNB);
272 LispAddressConvertorNB.convertGenericToLispAddresses(mapRegisterNB.getMapRegister());
273 } catch (Exception e) {
274 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
276 // Always request MapNotify
277 mapRegisterNB.getMapRegister().setWantMapNotify(true);
279 org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRegister mr = null;
281 mr = YangTransformerNB.transformMapRegister(mapRegisterNB.getMapRegister());
282 } catch (Exception e) {
283 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while converting the map register");
288 mapNotify = nbService.getMappingService().handleMapRegister(mr);
289 } catch (Exception e) {
290 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while registering the mapping");
293 if (mapNotify == null) {
294 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while registering the mapping");
296 return Response.status(Response.Status.OK).build();
300 * Retrieve a mapping from the LISP mapping system
302 * @param containerName
303 * name of the container context from which the mapping is going
306 * Instance-ID of the address (0 if none)
309 * Address Family of the address (IPv4, IPv6 or MAC)
312 * Address of type defined by afi
315 * Network mask length
317 * @return EidToLocatorRecord as a JSON object
323 * http://localhost:8080/lispflowmapping/nb/v2/default/mapping/0/1/10.0.0.1/32
328 private LispAddressGeneric parseAddressURL(int iid, int afi, String address, int mask) {
329 LispAddressGeneric eidGeneric = new LispAddressGeneric(afi, address);
332 eidGeneric = new LispAddressGeneric(AddressFamilyNumberEnum.LCAF.getIanaCode(), eidGeneric);
333 eidGeneric.setLcafType(LispCanonicalAddressFormatEnum.SEGMENT.getLispCode());
334 eidGeneric.setInstanceId(iid);
340 private LispAddressGeneric parseSrcDstAddressURL(int iid, int afi, String srcAdd, int srcML, String dstAdd, int dstML) {
341 LispAddressGeneric srcGeneric = new LispAddressGeneric(afi, srcAdd);
342 LispAddressGeneric dstGeneric = new LispAddressGeneric(afi, dstAdd);
345 srcGeneric = new LispAddressGeneric(AddressFamilyNumberEnum.LCAF.getIanaCode(), srcGeneric);
346 srcGeneric.setLcafType(LispCanonicalAddressFormatEnum.SEGMENT.getLispCode());
347 srcGeneric.setInstanceId(iid);
349 dstGeneric = new LispAddressGeneric(AddressFamilyNumberEnum.LCAF.getIanaCode(), dstGeneric);
350 dstGeneric.setLcafType(LispCanonicalAddressFormatEnum.SEGMENT.getLispCode());
351 dstGeneric.setInstanceId(iid);
354 LispAddressGeneric address = new LispAddressGeneric(AddressFamilyNumberEnum.LCAF.getIanaCode());
356 address.setLcafType(LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode());
357 address.setSrcAddress(srcGeneric);
358 address.setSrcMaskLength((byte) srcML);
359 address.setDstAddress(dstGeneric);
360 address.setDstMaskLength((byte) dstML);
365 @Path("/{containerName}/mapping/{iid}/{afi}/{address}/{mask}")
367 @Produces(MediaType.APPLICATION_JSON)
368 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
369 @ResponseCode(code = 400, condition = "Invalid data passed"),
370 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
371 @ResponseCode(code = 500, condition = "Internal Server Error: Get mapping failed"),
372 @ResponseCode(code = 503, condition = "Service unavailable") })
373 public org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord getMapping(@PathParam("containerName") String containerName,
374 @PathParam("iid") int iid, @PathParam("afi") int afi, @PathParam("address") String address, @PathParam("mask") int mask) {
376 handleContainerDoesNotExist(containerName);
378 authorizationCheck(containerName, Privilege.READ);
380 LispAddressGeneric eidGeneric = parseAddressURL(iid, afi, address, mask);
384 eid = LispAddressConvertorNB.convertToLispAddress(eidGeneric);
385 } catch (Exception e) {
386 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
389 EidToLocatorRecord record = lookupEID(containerName, mask, eid);
391 org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord legacyRecord = YangTransformerNB.reTransformEidToLocatorRecord(record);
392 LispAddressConvertorNB.convertRecordToGenericAddress(legacyRecord);
398 * Retrieve a mapping from the LISP mapping system, using Source-Destination
401 * @param containerName
402 * name of the container context from which the mapping is going
405 * Instance-ID of the addresses (0 if none)
408 * Address Family of the addresses (IPv4, IPv6 or MAC)
411 * Source address of type defined by afi
414 * Network mask length of the source address
417 * Destination address of type defined by afi
420 * Network mask length of the destination address
422 * @return EidToLocatorRecord as a JSON object
429 * http://localhost:8080/lispflowmapping/nb/v2/default/mapping/0/1/10.0.0.1/32/20.0.0.2/32
434 @Path("/{containerName}/mapping/{iid}/{afi}/{srcAdd}/{srcML}/{dstAdd}/{dstML}")
436 @Produces(MediaType.APPLICATION_JSON)
437 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
438 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
439 @ResponseCode(code = 503, condition = "Service unavailable") })
440 public org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord getMapping(@PathParam("containerName") String containerName,
441 @PathParam("iid") int iid, @PathParam("afi") int afi, @PathParam("srcAdd") String srcAdd, @PathParam("srcML") int srcML,
442 @PathParam("dstAdd") String dstAdd, @PathParam("dstML") int dstML) {
444 handleContainerDoesNotExist(containerName);
446 authorizationCheck(containerName, Privilege.READ);
448 LispAddressGeneric eidGeneric = parseSrcDstAddressURL(iid, afi, srcAdd, srcML, dstAdd, dstML);
450 int mask = 0; // Not used here
452 EidToLocatorRecord record = lookupEID(containerName, mask, LispAddressConvertorNB.convertToLispAddress(eidGeneric));
454 org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord legacyRecord = YangTransformerNB.reTransformEidToLocatorRecord(record);
455 LispAddressConvertorNB.convertRecordToGenericAddress(legacyRecord);
461 * Set the authentication key for an EID prefix
463 * @param containerName
464 * name of the container context in which the key needs to be set
466 * JSON object that contains the key information
468 * @return Text plain confirming reception
474 * http://localhost:8080/lispflowmapping/nb/v2/default/key
476 * Request body in JSON:
483 * "ipAddress" : "10.0.0.1",
491 @Path("/{containerName}/key")
493 @Consumes(MediaType.APPLICATION_JSON)
494 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
495 @ResponseCode(code = 400, condition = "Invalid data passed"),
496 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
497 @ResponseCode(code = 500, condition = "Internal Server Error: Addition of key failed"),
498 @ResponseCode(code = 503, condition = "Service unavailable") })
499 public Response addAuthKey(@PathParam("containerName") String containerName, @TypeHint(AuthKeyNB.class) AuthKeyNB authKeyNB) {
501 handleContainerDoesNotExist(containerName);
503 authorizationCheck(containerName, Privilege.WRITE);
505 LispAddress lispAddress;
507 lispAddress = LispAddressConvertorNB.convertToLispAddress(authKeyNB.getAddress());
508 } catch (Exception e) {
509 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
511 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
513 boolean success = false;
517 success = nbService.getMappingService().addAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress),
518 authKeyNB.getMaskLength(), authKeyNB.getKey());
519 } catch (Exception e) {
520 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while adding the key");
523 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while adding the key");
526 return Response.status(Response.Status.OK).build();
530 * Retrieve the key used to register an EID prefix
532 * @param containerName
533 * name of the container context from which the key is going to
537 * Address Family of the address (IPv4, IPv6 or MAC)
540 * Address of type defined by afi
543 * Network mask length
545 * @return AuthKeyNB as a JSON object
551 * http://localhost:8080/lispflowmapping/nb/v2/default/key/0/1/10.0.0.1/32
556 @Path("/{containerName}/key/{iid}/{afi}/{address}/{mask}")
558 @Produces(MediaType.APPLICATION_JSON)
559 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
560 @ResponseCode(code = 400, condition = "Invalid data passed"),
561 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
562 @ResponseCode(code = 500, condition = "Internal Server Error: Get key failed"),
563 @ResponseCode(code = 503, condition = "Service unavailable") })
564 public AuthKeyNB getAuthKey(@PathParam("containerName") String containerName, @PathParam("iid") int iid, @PathParam("afi") int afi,
565 @PathParam("address") String address, @PathParam("mask") int mask) {
567 handleContainerDoesNotExist(containerName);
569 authorizationCheck(containerName, Privilege.READ);
571 LispAddressGeneric lispAddressGeneric = parseAddressURL(iid, afi, address, mask);
573 LispAddress lispAddress;
576 lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
577 } catch (Exception e) {
578 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
580 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
584 key = nbService.getMappingService().getAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress), mask);
585 } catch (Exception e) {
586 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while retrieving the key");
590 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while retrieving the key");
593 AuthKeyNB authKeyNB = new AuthKeyNB();
595 authKeyNB.setKey(key);
596 authKeyNB.setAddress(lispAddressGeneric);
597 authKeyNB.setMaskLength(mask);
603 * Retrieve a key used to register a Source-Destination LCAF EID prefix
605 * @param containerName
606 * name of the container context from which the key is going to
610 * Address Family of the addresses (IPv4, IPv6 or MAC)
613 * Source address of type defined by afi
616 * Network mask length of the source address
619 * Destination address of type defined by afi
622 * Network mask length of the destination address
624 * @return AuthKeyNB as a JSON object
631 * http://localhost:8080/lispflowmapping/nb/v2/default/key/0/1/10.0.0.1/32/20.0.0.2/32
636 @Path("/{containerName}/key/{iid}/{afi}/{srcAdd}/{srcML}/{dstAdd}/{dstML}")
638 @Produces(MediaType.APPLICATION_JSON)
639 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
640 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
641 @ResponseCode(code = 503, condition = "Service unavailable") })
642 public AuthKeyNB getAuthKey(@PathParam("containerName") String containerName, @PathParam("iid") int iid, @PathParam("afi") int afi,
643 @PathParam("srcAdd") String srcAdd, @PathParam("srcML") int srcML, @PathParam("dstAdd") String dstAdd, @PathParam("dstML") int dstML) {
645 handleContainerDoesNotExist(containerName);
647 authorizationCheck(containerName, Privilege.READ);
649 LispAddressGeneric lispAddressGeneric = parseSrcDstAddressURL(iid, afi, srcAdd, srcML, dstAdd, dstML);
651 LispAddress lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
653 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
655 int mask = 0; // Not used here
657 LispAddressContainer yangAddress = YangTransformerNB.transformLispAddress(lispAddress);
659 String key = nbService.getMappingService().getAuthenticationKey(yangAddress, mask);
665 AuthKeyNB authKeyNB = new AuthKeyNB();
667 authKeyNB.setKey(key);
668 authKeyNB.setAddress(lispAddressGeneric);
669 authKeyNB.setMaskLength(mask);
675 * Delete the key used to register an EID prefix
677 * @param containerName
678 * name of the container context from which the key is going to
682 * Address Family of the address (IPv4, IPv6 or MAC)
685 * Address of type defined by afi
688 * Network mask length
690 * @return Text plain confirming deletion
696 * http://localhost:8080/lispflowmapping/nb/v2/default/key/0/1/10.0.0.1/32
701 @Path("/{containerName}/key/{iid}/{afi}/{address}/{mask}")
703 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
704 @ResponseCode(code = 400, condition = "Invalid data passed"),
705 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
706 @ResponseCode(code = 500, condition = "Internal Server Error: Delete key failed"),
707 @ResponseCode(code = 503, condition = "Service unavailable") })
708 public Response delAuthKey(@PathParam("containerName") String containerName, @PathParam("afi") int afi, @PathParam("iid") int iid,
709 @PathParam("address") String address, @PathParam("mask") int mask) {
711 handleContainerDoesNotExist(containerName);
713 authorizationCheck(containerName, Privilege.WRITE);
715 LispAddressGeneric lispAddressGeneric = parseAddressURL(iid, afi, address, mask);
717 LispAddress lispAddress;
719 lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
720 } catch (Exception e) {
721 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
724 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
726 boolean success = false;
728 success = nbService.getMappingService().removeAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress), mask);
729 } catch (Exception e) {
730 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while deleting the key");
734 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while deleting the key");
737 return Response.status(Response.Status.OK).build();
741 * Delete the key used to register an EID prefix
743 * @param containerName
744 * name of the container context from which the key is going to
748 * Address Family of the addresses (IPv4, IPv6 or MAC)
751 * Source address of type defined by afi
754 * Network mask length of the source address
757 * Destination address of type defined by afi
760 * Network mask length of the destination address
762 * @return AuthKeyNB as a JSON object
768 * http://localhost:8080/lispflowmapping/nb/v2/default/key/0/1/10.0.0.1/32/20.0.0.2/32
773 @Path("/{containerName}/key/{iid}/{afi}/{srcAdd}/{srcML}/{dstAdd}/{dstML}")
775 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
776 @ResponseCode(code = 400, condition = "Invalid data passed"),
777 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
778 @ResponseCode(code = 500, condition = "Internal Server Error: Delete key failed"),
779 @ResponseCode(code = 503, condition = "Service unavailable") })
780 public Response delAuthKey(@PathParam("containerName") String containerName, @PathParam("iid") int iid, @PathParam("afi") int afi,
781 @PathParam("srcAdd") String srcAdd, @PathParam("srcML") int srcML, @PathParam("dstAdd") String dstAdd, @PathParam("dstML") int dstML) {
783 handleContainerDoesNotExist(containerName);
785 authorizationCheck(containerName, Privilege.WRITE);
787 LispAddressGeneric lispAddressGeneric = parseSrcDstAddressURL(iid, afi, srcAdd, srcML, dstAdd, dstML);
789 LispAddress lispAddress;
791 lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
792 } catch (Exception e) {
793 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
796 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
798 int mask = 0; // Not used here
800 boolean success = false;
802 success = nbService.getMappingService().removeAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress), mask);
803 } catch (Exception e) {
804 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while deleting the key");
808 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while deleting the key");
811 return Response.status(Response.Status.OK).build();