View Javadoc

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.eid.container.Eid;
16  import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord;
17  import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
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.SiteId;
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.mapping.authkey.container.MappingAuthkey;
26  
27  /**
28   * @author Florin Coras
29   *
30   */
31  public final class DSBEInputUtil {
32      // Utility class, should not be instantiated
33      private DSBEInputUtil() {
34      }
35  
36      public static Mapping toMapping(MappingOrigin origin, Eid key, SiteId siteId, MappingRecord record) {
37          List<SiteId> siteIds = (siteId != null) ? Arrays.asList(siteId) : null;
38          return new MappingBuilder().setEidUri(new EidUri(LispAddressStringifier.getURIString(key)))
39                  .setOrigin(origin).setSiteId(siteIds).setMappingRecord(record).build();
40      }
41  
42      public static Mapping toMapping(MappingOrigin origin, Eid key) {
43          MappingBuilder mb = new MappingBuilder();
44          mb.setEidUri(new EidUri(LispAddressStringifier.getURIString(key)));
45          mb.setOrigin(origin);
46          mb.setMappingRecord(new MappingRecordBuilder().setEid(key).build());
47          return mb.build();
48      }
49  
50      public static AuthenticationKey toAuthenticationKey(Eid key, MappingAuthkey authKey) {
51          AuthenticationKeyBuilder akb = new AuthenticationKeyBuilder();
52          akb.setEidUri(new EidUri(LispAddressStringifier.getURIString(key)));
53          akb.setEid(key);
54          akb.setMappingAuthkey(authKey);
55          return akb.build();
56      }
57  }