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.Response;
22 import javax.ws.rs.core.SecurityContext;
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.InternalServerErrorException;
31 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
32 import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
33 import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
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.MapRequest;
42 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
43 import org.opendaylight.lispflowmapping.type.lisp.address.LispAddressGeneric;
44 import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
45 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapNotify;
46 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapReply;
47 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord;
48 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainer;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
53 public class LispMappingNorthbound implements ILispmappingNorthbound {
54 protected static final Logger LOG = LoggerFactory.getLogger(LispMappingNorthbound.class);
55 private IFlowMapping mappingService;
57 private String userName;
59 // Based on code from controller project
61 public void setSecurityContext(SecurityContext context) {
62 if (context != null && context.getUserPrincipal() != null) {
63 userName = context.getUserPrincipal().getName();
67 protected String getUserName() {
71 public IFlowMapping getMappingService() {
72 return this.mappingService;
75 void setFlowMappingService(IFlowMapping mappingService) {
76 LOG.trace("FlowMapping set in LispNorthbound");
77 this.mappingService = mappingService;
80 void unsetFlowMappingService(IFlowMapping mappingService) {
81 LOG.trace("LispDAO was unset in LISP Northbound");
82 this.mappingService = null;
86 LOG.trace("LISP Northbound Service is initialized!");
90 LOG.info("LISP Northbound Service is up!");
94 LOG.info("LISP Northbound Service is down!");
97 public void destroy() {
98 LOG.trace("LISP Northbound Service is destroyed!");
99 mappingService = null;
102 // Based on code from controller project
103 private void handleContainerDoesNotExist(String containerName) {
104 IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(IContainerManager.class, this);
105 if (containerManager == null) {
106 throw new ServiceUnavailableException("Container " + containerName + RestMessages.NOCONTAINER.toString());
109 List<String> containerNames = containerManager.getContainerNames();
110 for (String cName : containerNames) {
111 if (cName.trim().equalsIgnoreCase(containerName.trim())) {
116 throw new ResourceNotFoundException("Container " + containerName + " " + RestMessages.NOCONTAINER.toString());
119 private void authorizationCheck(String containerName, Privilege privilege) {
121 if (!NorthboundUtils.isAuthorized(getUserName(), containerName, privilege, this)) {
122 throw new UnauthorizedException("User is not authorized to perform this operation on container " + containerName);
126 private EidToLocatorRecord lookupEID(String containerName, int mask, LispAddress EID) {
128 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
130 MapRequest mapRequest = new MapRequest();
131 EidRecord EIDRecord = new EidRecord((byte) mask, EID);
132 mapRequest.addEidRecord(EIDRecord);
133 mapRequest.setSourceEid(new LispIpv4Address("127.0.0.1"));
135 org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRequest mr = YangTransformerNB.transformMapRequest(mapRequest);
138 mapReply = nbService.getMappingService().handleMapRequest(mr);
139 } catch (Exception e) {
140 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error looking up the EID");
143 if (mapReply == null) {
144 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error looking up the EID");
147 return mapReply.getEidToLocatorRecord().get(0);
150 private void keyCheck(IFlowMapping mappingService, MapRegisterNB mapRegisterNB) {
152 String usedKey = mapRegisterNB.getKey();
154 LispAddressGeneric lispAddressGeneric;
155 LispAddress lispAddress;
159 int numEidRecords = mapRegisterNB.getMapRegister().getEidToLocatorRecords().size();
161 for (int i = 0; i < numEidRecords; i++) {
163 lispAddressGeneric = mapRegisterNB.getMapRegister().getEidToLocatorRecords().get(i).getPrefixGeneric();
166 lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
167 } catch (Exception e) {
168 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
170 mask = mapRegisterNB.getMapRegister().getEidToLocatorRecords().get(i).getMaskLength();
172 storedKey = mappingService.getAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress), mask);
173 } catch (Exception e) {
174 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while retrieving the key");
177 if (!usedKey.equals(storedKey)) {
178 throw new UnauthorizedException("The key used to register the mapping " + "does not match with the stored key for that mapping");
184 * Add a mapping to the LISP mapping system
186 * @param containerName
187 * name of the container context in which the mapping needs to be
189 * @param mapRegisterNB
190 * JSON object that contains the mapping information
192 * @return Text plain confirming reception
198 * http://localhost:8080/lispflowmapping/nb/v2/default/mapping
200 * Request body in JSON:
206 * "wantMapNotify" : true,
207 * "proxyMapReply" : false,
208 * "eidToLocatorRecords" :
211 * "authoritative" : true,
214 * "ipAddress" : "10.0.0.1",
219 * "action" : "NoAction",
223 * "multicastPriority" : 3,
226 * "ipAddress" : "3.3.3.3",
230 * "multicastWeight" : 3,
231 * "rlocProbed" : false,
232 * "localLocator" : false,
247 @Path("/{containerName}/mapping")
249 @Consumes(MediaType.APPLICATION_JSON)
250 @StatusCodes({ @ResponseCode(code = 400, condition = "Invalid data passed"),
251 @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
252 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
253 @ResponseCode(code = 500, condition = "Internal Server Error: Addition of mapping failed"),
254 @ResponseCode(code = 503, condition = "Service unavailable") })
255 public Response addMapping(@PathParam("containerName") String containerName, @TypeHint(MapRegisterNB.class) MapRegisterNB mapRegisterNB) {
257 handleContainerDoesNotExist(containerName);
259 authorizationCheck(containerName, Privilege.WRITE);
261 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
264 keyCheck(nbService.getMappingService(), mapRegisterNB);
266 LispAddressConvertorNB.convertGenericToLispAddresses(mapRegisterNB.getMapRegister());
267 } catch (Exception e) {
268 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
270 // Always request MapNotify
271 mapRegisterNB.getMapRegister().setWantMapNotify(true);
273 org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRegister mr = null;
275 mr = YangTransformerNB.transformMapRegister(mapRegisterNB.getMapRegister());
276 } catch (Exception e) {
277 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while converting the map register");
282 mapNotify = nbService.getMappingService().handleMapRegister(mr);
283 } catch (Exception e) {
284 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while registering the mapping");
287 if (mapNotify == null) {
288 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while registering the mapping");
290 return Response.status(Response.Status.OK).build();
294 * Delete a mapping from the LISP Map-Server database
296 * @param containerName
297 * name of the container context from which the key is going to
301 * Address Family of the address (IPv4, IPv6 or MAC)
304 * Address of type defined by afi
307 * Network mask length
309 * @return Text plain confirming deletion
315 * http://localhost:8080/lispflowmapping/nb/v2/default/mapping/0/1/10.0.0.1/32
320 @Path("/{containerName}/mapping/{iid}/{afi}/{address}/{mask}")
322 @Consumes(MediaType.APPLICATION_JSON)
323 @StatusCodes({ @ResponseCode(code = 400, condition = "Invalid data passed"),
324 @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
325 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
326 @ResponseCode(code = 500, condition = "Internal Server Error: Addition of mapping failed"),
327 @ResponseCode(code = 503, condition = "Service unavailable") })
328 public Response deleteMapping(@PathParam("containerName") String containerName, @PathParam("iid") int iid,
329 @PathParam("afi") int afi, @PathParam("address") String address, @PathParam("mask") int mask) {
331 handleContainerDoesNotExist(containerName);
332 authorizationCheck(containerName, Privilege.WRITE);
334 LispAddressGeneric eidGeneric = parseAddressURL(iid, afi, address, mask);
337 eid = LispAddressConvertorNB.convertToLispAddress(eidGeneric);
338 } catch (Exception e) {
339 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
342 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
345 nbService.getMappingService().removeMapping(YangTransformerNB.transformLispAddress(eid), mask);
346 } catch (Exception e) {
347 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while deleting the key");
350 return Response.status(Response.Status.OK).build();
355 * Retrieve a mapping from the LISP mapping system
357 * @param containerName
358 * name of the container context from which the mapping is going
361 * Instance-ID of the address (0 if none)
364 * Address Family of the address (IPv4, IPv6 or MAC)
367 * Address of type defined by afi
370 * Network mask length
372 * @return EidToLocatorRecord as a JSON object
378 * http://localhost:8080/lispflowmapping/nb/v2/default/mapping/0/1/10.0.0.1/32
383 private LispAddressGeneric parseAddressURL(int iid, int afi, String address, int mask) {
384 LispAddressGeneric eidGeneric = new LispAddressGeneric(afi, address);
387 eidGeneric = new LispAddressGeneric(AddressFamilyNumberEnum.LCAF.getIanaCode(), eidGeneric);
388 eidGeneric.setLcafType(LispCanonicalAddressFormatEnum.SEGMENT.getLispCode());
389 eidGeneric.setInstanceId(iid);
395 private LispAddressGeneric parseSrcDstAddressURL(int iid, int afi, String srcAdd, int srcML, String dstAdd, int dstML) {
396 LispAddressGeneric srcGeneric = new LispAddressGeneric(afi, srcAdd);
397 LispAddressGeneric dstGeneric = new LispAddressGeneric(afi, dstAdd);
400 srcGeneric = new LispAddressGeneric(AddressFamilyNumberEnum.LCAF.getIanaCode(), srcGeneric);
401 srcGeneric.setLcafType(LispCanonicalAddressFormatEnum.SEGMENT.getLispCode());
402 srcGeneric.setInstanceId(iid);
404 dstGeneric = new LispAddressGeneric(AddressFamilyNumberEnum.LCAF.getIanaCode(), dstGeneric);
405 dstGeneric.setLcafType(LispCanonicalAddressFormatEnum.SEGMENT.getLispCode());
406 dstGeneric.setInstanceId(iid);
409 LispAddressGeneric address = new LispAddressGeneric(AddressFamilyNumberEnum.LCAF.getIanaCode());
411 address.setLcafType(LispCanonicalAddressFormatEnum.SOURCE_DEST.getLispCode());
412 address.setSrcAddress(srcGeneric);
413 address.setSrcMaskLength((byte) srcML);
414 address.setDstAddress(dstGeneric);
415 address.setDstMaskLength((byte) dstML);
420 @Path("/{containerName}/mapping/{iid}/{afi}/{address}/{mask}")
422 @Produces(MediaType.APPLICATION_JSON)
423 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
424 @ResponseCode(code = 400, condition = "Invalid data passed"),
425 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
426 @ResponseCode(code = 500, condition = "Internal Server Error: Get mapping failed"),
427 @ResponseCode(code = 503, condition = "Service unavailable") })
428 public org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord getMapping(@PathParam("containerName") String containerName,
429 @PathParam("iid") int iid, @PathParam("afi") int afi, @PathParam("address") String address, @PathParam("mask") int mask) {
431 handleContainerDoesNotExist(containerName);
433 authorizationCheck(containerName, Privilege.READ);
435 LispAddressGeneric eidGeneric = parseAddressURL(iid, afi, address, mask);
439 eid = LispAddressConvertorNB.convertToLispAddress(eidGeneric);
440 } catch (Exception e) {
441 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
444 EidToLocatorRecord record = lookupEID(containerName, mask, eid);
446 org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord legacyRecord = YangTransformerNB.reTransformEidToLocatorRecord(record);
447 LispAddressConvertorNB.convertRecordToGenericAddress(legacyRecord);
453 * Retrieve a mapping from the LISP mapping system, using Source-Destination
456 * @param containerName
457 * name of the container context from which the mapping is going
460 * Instance-ID of the addresses (0 if none)
463 * Address Family of the addresses (IPv4, IPv6 or MAC)
466 * Source address of type defined by afi
469 * Network mask length of the source address
472 * Destination address of type defined by afi
475 * Network mask length of the destination address
477 * @return EidToLocatorRecord as a JSON object
484 * http://localhost:8080/lispflowmapping/nb/v2/default/mapping/0/1/10.0.0.1/32/20.0.0.2/32
489 @Path("/{containerName}/mapping/{iid}/{afi}/{srcAdd}/{srcML}/{dstAdd}/{dstML}")
491 @Produces(MediaType.APPLICATION_JSON)
492 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
493 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
494 @ResponseCode(code = 503, condition = "Service unavailable") })
495 public org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord getMapping(@PathParam("containerName") String containerName,
496 @PathParam("iid") int iid, @PathParam("afi") int afi, @PathParam("srcAdd") String srcAdd, @PathParam("srcML") int srcML,
497 @PathParam("dstAdd") String dstAdd, @PathParam("dstML") int dstML) {
499 handleContainerDoesNotExist(containerName);
501 authorizationCheck(containerName, Privilege.READ);
503 LispAddressGeneric eidGeneric = parseSrcDstAddressURL(iid, afi, srcAdd, srcML, dstAdd, dstML);
505 int mask = 0; // Not used here
507 EidToLocatorRecord record = lookupEID(containerName, mask, LispAddressConvertorNB.convertToLispAddress(eidGeneric));
509 org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord legacyRecord = YangTransformerNB.reTransformEidToLocatorRecord(record);
510 LispAddressConvertorNB.convertRecordToGenericAddress(legacyRecord);
516 * Set the authentication key for an EID prefix
518 * @param containerName
519 * name of the container context in which the key needs to be set
521 * JSON object that contains the key information
523 * @return Text plain confirming reception
529 * http://localhost:8080/lispflowmapping/nb/v2/default/key
531 * Request body in JSON:
538 * "ipAddress" : "10.0.0.1",
546 @Path("/{containerName}/key")
548 @Consumes(MediaType.APPLICATION_JSON)
549 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
550 @ResponseCode(code = 400, condition = "Invalid data passed"),
551 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
552 @ResponseCode(code = 500, condition = "Internal Server Error: Addition of key failed"),
553 @ResponseCode(code = 503, condition = "Service unavailable") })
554 public Response addAuthKey(@PathParam("containerName") String containerName, @TypeHint(AuthKeyNB.class) AuthKeyNB authKeyNB) {
556 handleContainerDoesNotExist(containerName);
558 authorizationCheck(containerName, Privilege.WRITE);
560 LispAddress lispAddress;
562 lispAddress = LispAddressConvertorNB.convertToLispAddress(authKeyNB.getAddress());
563 } catch (Exception e) {
564 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
566 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
570 nbService.getMappingService().addAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress), authKeyNB.getMaskLength(),
572 } catch (Exception e) {
573 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while adding the key");
576 return Response.status(Response.Status.OK).build();
580 * Retrieve the key used to register an EID prefix
582 * @param containerName
583 * name of the container context from which the key is going to
587 * Address Family of the address (IPv4, IPv6 or MAC)
590 * Address of type defined by afi
593 * Network mask length
595 * @return AuthKeyNB as a JSON object
601 * http://localhost:8080/lispflowmapping/nb/v2/default/key/0/1/10.0.0.1/32
606 @Path("/{containerName}/key/{iid}/{afi}/{address}/{mask}")
608 @Produces(MediaType.APPLICATION_JSON)
609 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
610 @ResponseCode(code = 400, condition = "Invalid data passed"),
611 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
612 @ResponseCode(code = 500, condition = "Internal Server Error: Get key failed"),
613 @ResponseCode(code = 503, condition = "Service unavailable") })
614 public AuthKeyNB getAuthKey(@PathParam("containerName") String containerName, @PathParam("iid") int iid, @PathParam("afi") int afi,
615 @PathParam("address") String address, @PathParam("mask") int mask) {
617 handleContainerDoesNotExist(containerName);
619 authorizationCheck(containerName, Privilege.READ);
621 LispAddressGeneric lispAddressGeneric = parseAddressURL(iid, afi, address, mask);
623 LispAddress lispAddress;
626 lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
627 } catch (Exception e) {
628 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
630 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
634 key = nbService.getMappingService().getAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress), mask);
635 } catch (Exception e) {
636 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while retrieving the key");
640 throw new ResourceNotFoundException(RestMessages.NORESOURCE.toString() + " : The requested key was not found");
643 AuthKeyNB authKeyNB = new AuthKeyNB();
645 authKeyNB.setKey(key);
646 authKeyNB.setAddress(lispAddressGeneric);
647 authKeyNB.setMaskLength(mask);
653 * Retrieve a key used to register a Source-Destination LCAF EID prefix
655 * @param containerName
656 * name of the container context from which the key is going to
660 * Address Family of the addresses (IPv4, IPv6 or MAC)
663 * Source address of type defined by afi
666 * Network mask length of the source address
669 * Destination address of type defined by afi
672 * Network mask length of the destination address
674 * @return AuthKeyNB as a JSON object
681 * http://localhost:8080/lispflowmapping/nb/v2/default/key/0/1/10.0.0.1/32/20.0.0.2/32
686 @Path("/{containerName}/key/{iid}/{afi}/{srcAdd}/{srcML}/{dstAdd}/{dstML}")
688 @Produces(MediaType.APPLICATION_JSON)
689 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
690 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
691 @ResponseCode(code = 503, condition = "Service unavailable") })
692 public AuthKeyNB getAuthKey(@PathParam("containerName") String containerName, @PathParam("iid") int iid, @PathParam("afi") int afi,
693 @PathParam("srcAdd") String srcAdd, @PathParam("srcML") int srcML, @PathParam("dstAdd") String dstAdd, @PathParam("dstML") int dstML) {
695 handleContainerDoesNotExist(containerName);
697 authorizationCheck(containerName, Privilege.READ);
699 LispAddressGeneric lispAddressGeneric = parseSrcDstAddressURL(iid, afi, srcAdd, srcML, dstAdd, dstML);
701 LispAddress lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
703 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
705 int mask = 0; // Not used here
707 LispAddressContainer yangAddress = YangTransformerNB.transformLispAddress(lispAddress);
709 String key = nbService.getMappingService().getAuthenticationKey(yangAddress, mask);
712 throw new ResourceNotFoundException(RestMessages.NORESOURCE.toString() + " : The requested key was not found");
715 AuthKeyNB authKeyNB = new AuthKeyNB();
717 authKeyNB.setKey(key);
718 authKeyNB.setAddress(lispAddressGeneric);
719 authKeyNB.setMaskLength(mask);
725 * Delete the key used to register an EID prefix
727 * @param containerName
728 * name of the container context from which the key is going to
732 * Address Family of the address (IPv4, IPv6 or MAC)
735 * Address of type defined by afi
738 * Network mask length
740 * @return Text plain confirming deletion
746 * http://localhost:8080/lispflowmapping/nb/v2/default/key/0/1/10.0.0.1/32
751 @Path("/{containerName}/key/{iid}/{afi}/{address}/{mask}")
753 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
754 @ResponseCode(code = 400, condition = "Invalid data passed"),
755 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
756 @ResponseCode(code = 500, condition = "Internal Server Error: Delete key failed"),
757 @ResponseCode(code = 503, condition = "Service unavailable") })
758 public Response delAuthKey(@PathParam("containerName") String containerName, @PathParam("afi") int afi, @PathParam("iid") int iid,
759 @PathParam("address") String address, @PathParam("mask") int mask) {
761 handleContainerDoesNotExist(containerName);
763 authorizationCheck(containerName, Privilege.WRITE);
765 LispAddressGeneric lispAddressGeneric = parseAddressURL(iid, afi, address, mask);
767 LispAddress lispAddress;
769 lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
770 } catch (Exception e) {
771 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
774 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
777 nbService.getMappingService().removeAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress), mask);
778 } catch (Exception e) {
779 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while deleting the key");
782 return Response.status(Response.Status.OK).build();
786 * Delete the key used to register an EID prefix
788 * @param containerName
789 * name of the container context from which the key is going to
793 * Address Family of the addresses (IPv4, IPv6 or MAC)
796 * Source address of type defined by afi
799 * Network mask length of the source address
802 * Destination address of type defined by afi
805 * Network mask length of the destination address
807 * @return AuthKeyNB as a JSON object
813 * http://localhost:8080/lispflowmapping/nb/v2/default/key/0/1/10.0.0.1/32/20.0.0.2/32
818 @Path("/{containerName}/key/{iid}/{afi}/{srcAdd}/{srcML}/{dstAdd}/{dstML}")
820 @StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
821 @ResponseCode(code = 400, condition = "Invalid data passed"),
822 @ResponseCode(code = 404, condition = "The containerName passed was not found"),
823 @ResponseCode(code = 500, condition = "Internal Server Error: Delete key failed"),
824 @ResponseCode(code = 503, condition = "Service unavailable") })
825 public Response delAuthKey(@PathParam("containerName") String containerName, @PathParam("iid") int iid, @PathParam("afi") int afi,
826 @PathParam("srcAdd") String srcAdd, @PathParam("srcML") int srcML, @PathParam("dstAdd") String dstAdd, @PathParam("dstML") int dstML) {
828 handleContainerDoesNotExist(containerName);
830 authorizationCheck(containerName, Privilege.WRITE);
832 LispAddressGeneric lispAddressGeneric = parseSrcDstAddressURL(iid, afi, srcAdd, srcML, dstAdd, dstML);
834 LispAddress lispAddress;
836 lispAddress = LispAddressConvertorNB.convertToLispAddress(lispAddressGeneric);
837 } catch (Exception e) {
838 throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Address is not valid");
841 ILispmappingNorthbound nbService = (ILispmappingNorthbound) ServiceHelper.getInstance(ILispmappingNorthbound.class, containerName, this);
843 int mask = 0; // Not used here
846 nbService.getMappingService().removeAuthenticationKey(YangTransformerNB.transformLispAddress(lispAddress), mask);
847 } catch (Exception e) {
848 throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString() + " : There was an error while deleting the key");
851 return Response.status(Response.Status.OK).build();