1
2
3
4
5
6
7
8 package org.opendaylight.lispflowmapping.implementation.util;
9
10 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.InstanceId;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.EidUri;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.VniUri;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKeyKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.MappingKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.VirtualNetworkIdentifier;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.VirtualNetworkIdentifierKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 import com.google.common.base.Preconditions;
27
28
29
30
31
32
33
34
35 public final class InstanceIdentifierUtil {
36
37 private InstanceIdentifierUtil() {
38 }
39
40 public static InstanceIdentifier<AuthenticationKey> createAuthenticationKeyIid(Eid eid) {
41 Preconditions.checkNotNull(eid, "Key needs and EID entry!");
42
43 VirtualNetworkIdentifierKey vniKey = new VirtualNetworkIdentifierKey(new VniUri(Long.toString(getLispInstanceId(eid))));
44 AuthenticationKeyKey authKeyKey = new AuthenticationKeyKey(new EidUri(getURIAddressString(eid)));
45 return InstanceIdentifier.create(MappingDatabase.class)
46 .child(VirtualNetworkIdentifier.class, vniKey).child(AuthenticationKey.class, authKeyKey);
47 }
48
49 public static InstanceIdentifier<Mapping> createMappingIid(Eid eid, MappingOrigin orig) {
50 Preconditions.checkNotNull(eid, "Mapping needs an EID entry!");
51
52 VirtualNetworkIdentifierKey vniKey = new VirtualNetworkIdentifierKey(new VniUri(Long.toString(getLispInstanceId(eid))));
53 MappingKey eidKey = new MappingKey(new EidUri(getURIAddressString(eid)), orig);
54 return InstanceIdentifier.create(MappingDatabase.class)
55 .child(VirtualNetworkIdentifier.class, vniKey).child(Mapping.class, eidKey);
56 }
57
58 private static long getLispInstanceId(Eid eid) {
59 Address address = eid.getAddress();
60 if (address instanceof InstanceId) {
61 return ((InstanceId) address).getInstanceId().getIid().getValue();
62 } else if (eid.getVirtualNetworkId() != null) {
63 return eid.getVirtualNetworkId().getValue();
64 }
65 return 0L;
66 }
67
68 private static String getURIAddressString(Eid eid) {
69 return LispAddressStringifier.getURIString(eid);
70 }
71 }