Store southbound xTR-ID sub-mappings in datastore
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / util / DSBEInputUtil.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.lispflowmapping.implementation.util;
10
11 import java.util.Arrays;
12 import java.util.List;
13
14 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.EidUri;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.XtrIdUri;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKeyBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.MappingBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.mapping.XtrIdMapping;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.mapping.XtrIdMappingBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
28
29 /**
30  * @author Florin Coras
31  *
32  */
33 public final class DSBEInputUtil {
34     // Utility class, should not be instantiated
35     private DSBEInputUtil() {
36     }
37
38     public static Mapping toMapping(MappingOrigin origin, Eid key, SiteId siteId, MappingRecord record) {
39         List<SiteId> siteIds = (siteId != null) ? Arrays.asList(siteId) : null;
40         return new MappingBuilder().setEidUri(new EidUri(LispAddressStringifier.getURIString(key)))
41                 .setOrigin(origin).setSiteId(siteIds).setMappingRecord(record).build();
42     }
43
44     public static Mapping toMapping(MappingOrigin origin, Eid key) {
45         MappingBuilder mb = new MappingBuilder();
46         mb.setEidUri(new EidUri(LispAddressStringifier.getURIString(key)));
47         mb.setOrigin(origin);
48         return mb.build();
49     }
50
51     public static XtrIdMapping toXtrIdMapping(MappingRecord record) {
52         return new XtrIdMappingBuilder().setXtrIdUri(
53                 new XtrIdUri(LispAddressStringifier.getURIString(record.getXtrId()))).setMappingRecord(record).build();
54     }
55
56     public static AuthenticationKey toAuthenticationKey(Eid key, MappingAuthkey authKey) {
57         AuthenticationKeyBuilder akb = new AuthenticationKeyBuilder();
58         akb.setEidUri(new EidUri(LispAddressStringifier.getURIString(key)));
59         akb.setEid(key);
60         akb.setMappingAuthkey(authKey);
61         return akb.build();
62     }
63 }