2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.test;
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.AbstractObjectRegistration;
29 import org.opendaylight.yangtools.concepts.ObjectRegistration;
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;
36 public class OpenflowpluginMeterTestServiceProvider implements AutoCloseable,
38 private static final Logger LOG = LoggerFactory
39 .getLogger(OpenflowpluginMeterTestServiceProvider.class);
40 private DataBroker dataService;
41 private RoutedRpcRegistration<SalMeterService> meterRegistration;
42 private NotificationProviderService notificationService;
47 * @return {@link #dataService}
49 public DataBroker getDataService() {
50 return this.dataService;
54 * set {@link #dataService}
58 public void setDataService(final DataBroker dataService) {
59 this.dataService = dataService;
63 * get meter registration
65 * @return {@link #meterRegistration}
67 public RoutedRpcRegistration<SalMeterService> getMeterRegistration() {
68 return this.meterRegistration;
72 * set {@link #meterRegistration}
74 * @param meterRegistration
76 public void setMeterRegistration(
77 final RoutedRpcRegistration<SalMeterService> meterRegistration) {
78 this.meterRegistration = meterRegistration;
82 * get notification service
84 * @return {@link #notificationService}
86 public NotificationProviderService getNotificationService() {
87 return this.notificationService;
91 * set {@link #notificationService}
93 * @param notificationService
95 public void setNotificationService(
96 final NotificationProviderService notificationService) {
97 this.notificationService = notificationService;
100 public void start() {
101 OpenflowpluginMeterTestServiceProvider.LOG
102 .info("SalMeterServiceProvider Started.");
108 * @see java.lang.AutoCloseable#close()
110 public void close() {
111 OpenflowpluginMeterTestServiceProvider.LOG
112 .info("SalMeterServiceProvide stopped.");
113 meterRegistration.close();
120 * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
122 * #addMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter
123 * .service.rev130918.AddMeterInput)
125 public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
126 String plus = ("addMeter - " + input);
127 OpenflowpluginMeterTestServiceProvider.LOG.info(plus);
135 * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
137 * #removeMeter(org.opendaylight.yang.gen.v1.urn.opendaylight
138 * .meter.service.rev130918.RemoveMeterInput)
140 public Future<RpcResult<RemoveMeterOutput>> removeMeter(
141 final RemoveMeterInput input) {
142 String plus = ("removeMeter - " + input);
143 OpenflowpluginMeterTestServiceProvider.LOG.info(plus);
151 * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
153 * #updateMeter(org.opendaylight.yang.gen.v1.urn.opendaylight
154 * .meter.service.rev130918.UpdateMeterInput)
156 public Future<RpcResult<UpdateMeterOutput>> updateMeter(
157 final UpdateMeterInput input) {
158 String plus = ("updateMeter - " + input);
159 OpenflowpluginMeterTestServiceProvider.LOG.info(plus);
165 * @return {@link ObjectRegistration}
167 public ObjectRegistration<OpenflowpluginMeterTestServiceProvider> register(
168 final ProviderContext ctx) {
170 RoutedRpcRegistration<SalMeterService> addRoutedRpcImplementation = ctx
171 .<SalMeterService> addRoutedRpcImplementation(
172 SalMeterService.class, this);
174 setMeterRegistration(addRoutedRpcImplementation);
176 InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier
177 .<Nodes> builder(Nodes.class);
179 NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
180 NodeKey nodeKey = new NodeKey(nodeId);
182 InstanceIdentifierBuilder<Node> nodeIndentifier = builder1
183 .<Node, NodeKey> child(Node.class, nodeKey);
185 InstanceIdentifier<Node> instance = nodeIndentifier.build();
187 meterRegistration.registerPath(NodeContext.class, instance);
189 RoutedRpcRegistration<SalMeterService> meterRegistration1 = this
190 .getMeterRegistration();
192 return new AbstractObjectRegistration<OpenflowpluginMeterTestServiceProvider>(this) {
195 protected void removeRegistration() {
196 meterRegistration1.close();