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 com.google.common.util.concurrent.ListenableFuture;
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.flow.service.rev130819.AddFlowInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
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 OpenflowpluginTestServiceProvider implements AutoCloseable,
39 private static final Logger LOG = LoggerFactory
40 .getLogger(OpenflowpluginTestServiceProvider.class);
42 private DataBroker dataService;
43 private RoutedRpcRegistration<SalFlowService> flowRegistration;
44 private NotificationProviderService notificationProviderService;
49 * @return {@link #dataService}
51 public DataBroker getDataService() {
56 * Set {@link #dataService}.
58 public void setDataService(final DataBroker dataService) {
59 this.dataService = dataService;
63 * Get flow registration.
65 * @return {@link #flowRegistration}
67 public RoutedRpcRegistration<SalFlowService> getFlowRegistration() {
68 return flowRegistration;
72 * Set {@link #flowRegistration}.
74 public void setFlowRegistration(
75 final RoutedRpcRegistration<SalFlowService> flowRegistration) {
76 this.flowRegistration = flowRegistration;
80 * Get notification service.
82 * @return {@link #notificationProviderService}
84 public NotificationProviderService getNotificationService() {
85 return notificationProviderService;
89 * Set {@link #notificationProviderService}.
91 public void setNotificationService(final NotificationProviderService service) {
92 this.notificationProviderService = service;
96 OpenflowpluginTestServiceProvider.LOG
97 .info("SalFlowServiceProvider Started.");
103 * @see java.lang.AutoCloseable#close()
106 public void close() throws Exception {
107 OpenflowpluginTestServiceProvider.LOG
108 .info("SalFlowServiceProvide stopped.");
109 flowRegistration.close();
116 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
118 * #addFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.
119 * service.rev130819.AddFlowInput)
122 public ListenableFuture<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
123 String plus = "addFlow - " + input;
124 OpenflowpluginTestServiceProvider.LOG.info(plus);
132 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
134 * #removeFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
135 * .service.rev130819.RemoveFlowInput)
138 public ListenableFuture<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
139 String plus = "removeFlow - " + input;
140 OpenflowpluginTestServiceProvider.LOG.info(plus);
148 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
150 * #updateFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
151 * .service.rev130819.UpdateFlowInput)
154 public ListenableFuture<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
155 String plus = "updateFlow - " + input;
156 OpenflowpluginTestServiceProvider.LOG.info(plus);
160 public ObjectRegistration<OpenflowpluginTestServiceProvider> register(
161 final ProviderContext ctx) {
162 RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation = ctx
163 .<SalFlowService>addRoutedRpcImplementation(
164 SalFlowService.class, this);
166 setFlowRegistration(addRoutedRpcImplementation);
168 InstanceIdentifierBuilder<Nodes> builderII = InstanceIdentifier
169 .<Nodes>builder(Nodes.class);
171 NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
172 NodeKey nodeKey = new NodeKey(nodeId);
174 InstanceIdentifierBuilder<Node> nodeIdentifier = builderII
175 .<Node, NodeKey>child(Node.class, nodeKey);
177 InstanceIdentifier<Node> instance = nodeIdentifier.build();
179 flowRegistration.registerPath(NodeContext.class, instance);
181 RoutedRpcRegistration<SalFlowService> flowRegistration2 = getFlowRegistration();
183 return new AbstractObjectRegistration<OpenflowpluginTestServiceProvider>(this) {
185 protected void removeRegistration() {
186 flowRegistration2.close();