Do not use RpcService in LISPMAP components
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / MappingServiceShell.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 package org.opendaylight.lispflowmapping.implementation;
9
10 import javax.inject.Inject;
11 import javax.inject.Singleton;
12 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
13 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServiceShell;
14 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
20 import org.opendaylight.yangtools.yang.common.Uint16;
21 import org.osgi.service.component.annotations.Activate;
22 import org.osgi.service.component.annotations.Component;
23 import org.osgi.service.component.annotations.Reference;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * Implement Karaf commands to interact with the Mapping Service.
29  *
30  * @author Lorand Jakab
31  *
32  */
33 @Singleton
34 @Component(service = IMappingServiceShell.class, immediate = true, property = "type=default")
35 public class MappingServiceShell implements IMappingServiceShell {
36     protected static final Logger LOG = LoggerFactory.getLogger(MappingServiceShell.class);
37
38     private final IMappingService mappingService;
39
40     @Inject
41     @Activate
42     public MappingServiceShell(final @Reference IMappingService mappingService) {
43         this.mappingService = mappingService;
44     }
45
46     @Override
47     public String printMappings() {
48         return mappingService.printMappings();
49     }
50
51     @Override
52     public String prettyPrintMappings() {
53         return mappingService.prettyPrintMappings();
54     }
55
56     @Override
57     public String printKeys() {
58         return mappingService.printKeys();
59     }
60
61     @Override
62     public String prettyPrintKeys() {
63         return mappingService.prettyPrintKeys();
64     }
65
66     @Override
67     public void addDefaultKeyIPv4() {
68         Eid eid = LispAddressUtil.toEid(new Ipv4Prefix("0.0.0.0/0"), null);
69         MappingAuthkey key = new MappingAuthkeyBuilder().setKeyType(Uint16.ONE).setKeyString("password").build();
70         mappingService.addAuthenticationKey(eid, key);
71     }
72
73     @Override
74     public void addDefaultKeyIPv6() {
75         Eid eid = LispAddressUtil.toEid(new Ipv6Prefix("::0/0"), null);
76         MappingAuthkey key = new MappingAuthkeyBuilder().setKeyType(Uint16.ONE).setKeyString("password").build();
77         mappingService.addAuthenticationKey(eid, key);
78     }
79 }