a560f657c7ee27aa09c92428fb158c94e31e0faf
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginMeterTestServiceProvider.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  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.openflowplugin.test;
10
11 import java.util.concurrent.Future;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
15 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
28 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
29 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration.CompositeObjectRegistrationBuilder;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class OpenflowpluginMeterTestServiceProvider implements AutoCloseable,
37         SalMeterService {
38     private static final Logger LOG = LoggerFactory
39             .getLogger(OpenflowpluginMeterTestServiceProvider.class);
40     private DataBroker dataService;
41     private RoutedRpcRegistration<SalMeterService> meterRegistration;
42     private NotificationProviderService notificationService;
43
44     /**
45      * get data service
46      *
47      * @return {@link #dataService}
48      */
49     public DataBroker getDataService() {
50         return this.dataService;
51     }
52
53     /**
54      * set {@link #dataService}
55      *
56      * @param dataService
57      */
58     public void setDataService(final DataBroker dataService) {
59         this.dataService = dataService;
60     }
61
62     /**
63      * get meter registration
64      *
65      * @return {@link #meterRegistration}
66      */
67     public RoutedRpcRegistration<SalMeterService> getMeterRegistration() {
68         return this.meterRegistration;
69     }
70
71     /**
72      * set {@link #meterRegistration}
73      *
74      * @param meterRegistration
75      */
76     public void setMeterRegistration(
77             final RoutedRpcRegistration<SalMeterService> meterRegistration) {
78         this.meterRegistration = meterRegistration;
79     }
80
81     /**
82      * get notification service
83      *
84      * @return {@link #notificationService}
85      */
86     public NotificationProviderService getNotificationService() {
87         return this.notificationService;
88     }
89
90     /**
91      * set {@link #notificationService}
92      *
93      * @param notificationService
94      */
95     public void setNotificationService(
96             final NotificationProviderService notificationService) {
97         this.notificationService = notificationService;
98     }
99
100     public void start() {
101         OpenflowpluginMeterTestServiceProvider.LOG
102                 .info("SalMeterServiceProvider Started.");
103     }
104
105     /*
106      * (non-Javadoc)
107      *
108      * @see java.lang.AutoCloseable#close()
109      */
110     public void close() {
111         OpenflowpluginMeterTestServiceProvider.LOG
112                 .info("SalMeterServiceProvide stopped.");
113         meterRegistration.close();
114     }
115
116     /*
117      * (non-Javadoc)
118      *
119      * @see
120      * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
121      * .SalMeterService
122      * #addMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter
123      * .service.rev130918.AddMeterInput)
124      */
125     public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
126         String plus = ("addMeter - " + input);
127         OpenflowpluginMeterTestServiceProvider.LOG.info(plus);
128         return null;
129     }
130
131     /*
132      * (non-Javadoc)
133      *
134      * @see
135      * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
136      * .SalMeterService
137      * #removeMeter(org.opendaylight.yang.gen.v1.urn.opendaylight
138      * .meter.service.rev130918.RemoveMeterInput)
139      */
140     public Future<RpcResult<RemoveMeterOutput>> removeMeter(
141             final RemoveMeterInput input) {
142         String plus = ("removeMeter - " + input);
143         OpenflowpluginMeterTestServiceProvider.LOG.info(plus);
144         return null;
145     }
146
147     /*
148      * (non-Javadoc)
149      *
150      * @see
151      * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
152      * .SalMeterService
153      * #updateMeter(org.opendaylight.yang.gen.v1.urn.opendaylight
154      * .meter.service.rev130918.UpdateMeterInput)
155      */
156     public Future<RpcResult<UpdateMeterOutput>> updateMeter(
157             final UpdateMeterInput input) {
158         String plus = ("updateMeter - " + input);
159         OpenflowpluginMeterTestServiceProvider.LOG.info(plus);
160         return null;
161     }
162
163     /**
164      * @param ctx
165      * @return {@link CompositeObjectRegistrationBuilder #toInstance()}
166      */
167     public CompositeObjectRegistration<OpenflowpluginMeterTestServiceProvider> register(
168             final ProviderContext ctx) {
169         CompositeObjectRegistrationBuilder<OpenflowpluginMeterTestServiceProvider> builder = CompositeObjectRegistration
170                 .<OpenflowpluginMeterTestServiceProvider> builderFor(this);
171
172         RoutedRpcRegistration<SalMeterService> addRoutedRpcImplementation = ctx
173                 .<SalMeterService> addRoutedRpcImplementation(
174                         SalMeterService.class, this);
175
176         setMeterRegistration(addRoutedRpcImplementation);
177
178         InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier
179                 .<Nodes> builder(Nodes.class);
180
181         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
182         NodeKey nodeKey = new NodeKey(nodeId);
183
184         InstanceIdentifierBuilder<Node> nodeIndentifier = builder1
185                 .<Node, NodeKey> child(Node.class, nodeKey);
186
187         InstanceIdentifier<Node> instance = nodeIndentifier.build();
188
189         meterRegistration.registerPath(NodeContext.class, instance);
190
191         RoutedRpcRegistration<SalMeterService> meterRegistration1 = this
192                 .getMeterRegistration();
193
194         builder.add(meterRegistration1);
195
196         return builder.build();
197     }
198
199 }