2 * Copyright (c) 2014 Contextream, 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.southbound.util;
10 import java.net.Inet4Address;
11 import java.net.InetAddress;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifynotification.MapNotify;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifynotification.MapNotifyBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegister;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplynotification.MapReply;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplynotification.MapReplyBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequest;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequestnotification.MapRequestBuilder;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
25 public class LispNotificationHelper {
26 public static MapRegister convertMapRegister(
27 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister mapRegister) {
28 return new MapRegisterBuilder().setAuthenticationData(mapRegister.getAuthenticationData())
29 .setEidToLocatorRecord(mapRegister.getEidToLocatorRecord()).setKeyId(mapRegister.getKeyId())
30 .setNonce(mapRegister.getNonce()).setProxyMapReply(mapRegister.isProxyMapReply())
31 .setWantMapNotify(mapRegister.isWantMapNotify()).setXtrSiteIdPresent(mapRegister.isXtrSiteIdPresent())
32 .setXtrId(mapRegister.getXtrId()).setSiteId(mapRegister.getSiteId()).build();
35 public static MapNotify convertMapNotify(
36 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify mapNotify) {
37 return new MapNotifyBuilder().setAuthenticationData(mapNotify.getAuthenticationData())
38 .setEidToLocatorRecord(mapNotify.getEidToLocatorRecord()).setKeyId(mapNotify.getKeyId())
39 .setNonce(mapNotify.getNonce()).setXtrSiteIdPresent(mapNotify.isXtrSiteIdPresent())
40 .setXtrId(mapNotify.getXtrId()).setSiteId(mapNotify.getSiteId()).build();
43 public static MapRequest convertMapRequest(
44 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRequest mapRequest) {
45 return new MapRequestBuilder().setAuthoritative(mapRequest.isAuthoritative())
46 .setEidRecord(mapRequest.getEidRecord()).setItrRloc(mapRequest.getItrRloc())
47 .setMapDataPresent(mapRequest.isMapDataPresent()).setMapReply(mapRequest.getMapReply())
48 .setNonce(mapRequest.getNonce()).setPitr(mapRequest.isPitr()).setProbe(mapRequest.isProbe())
49 .setSmr(mapRequest.isSmr()).setSmrInvoked(mapRequest.isSmrInvoked())
50 .setSourceEid(mapRequest.getSourceEid()).build();
53 public static MapReply convertMapReply(
54 org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapReply mapReply) {
55 return new MapReplyBuilder().setEchoNonceEnabled(mapReply.isEchoNonceEnabled())
56 .setEidToLocatorRecord(mapReply.getEidToLocatorRecord()).setNonce(mapReply.getNonce())
57 .setProbe(mapReply.isProbe()).setSecurityEnabled(mapReply.isSecurityEnabled()).build();
60 public static IpAddress getIpAddressFromInetAddress(InetAddress inetAddress) {
61 if (inetAddress == null) {
62 inetAddress = InetAddress.getLoopbackAddress();
64 if (inetAddress instanceof Inet4Address) {
65 return new IpAddress(new Ipv4Address(inetAddress.getHostAddress()));
67 return new IpAddress(new Ipv6Address(inetAddress.getHostAddress()));