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.RoutedRpcRegistration;
14 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
15 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
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 final DataBroker dataService;
43 private RoutedRpcRegistration<SalFlowService> flowRegistration;
44 private final NotificationProviderService notificationProviderService;
46 public OpenflowpluginTestServiceProvider(DataBroker dataService,
47 NotificationProviderService notificationProviderService) {
48 this.dataService = dataService;
49 this.notificationProviderService = notificationProviderService;
55 * @return {@link #dataService}
57 public DataBroker getDataService() {
62 * Get flow registration.
64 * @return {@link #flowRegistration}
66 public RoutedRpcRegistration<SalFlowService> getFlowRegistration() {
67 return flowRegistration;
71 * Set {@link #flowRegistration}.
73 public void setFlowRegistration(
74 final RoutedRpcRegistration<SalFlowService> flowRegistration) {
75 this.flowRegistration = flowRegistration;
79 * Get notification service.
81 * @return {@link #notificationProviderService}
83 public NotificationProviderService getNotificationService() {
84 return notificationProviderService;
90 * @see java.lang.AutoCloseable#close()
93 public void close() throws Exception {
94 OpenflowpluginTestServiceProvider.LOG
95 .info("SalFlowServiceProvide stopped.");
96 flowRegistration.close();
103 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
105 * #addFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.
106 * service.rev130819.AddFlowInput)
109 public ListenableFuture<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
110 OpenflowpluginTestServiceProvider.LOG.info("addFlow - {}", input);
118 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
120 * #removeFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
121 * .service.rev130819.RemoveFlowInput)
124 public ListenableFuture<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
125 OpenflowpluginTestServiceProvider.LOG.info("removeFlow - {}", input);
133 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
135 * #updateFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
136 * .service.rev130819.UpdateFlowInput)
139 public ListenableFuture<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
140 OpenflowpluginTestServiceProvider.LOG.info("updateFlow - {}", input);
144 public ObjectRegistration<OpenflowpluginTestServiceProvider> register(RpcProviderRegistry rpcRegistry) {
145 RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation =
146 rpcRegistry.addRoutedRpcImplementation(SalFlowService.class, this);
148 setFlowRegistration(addRoutedRpcImplementation);
150 InstanceIdentifierBuilder<Nodes> builderII = InstanceIdentifier
151 .<Nodes>builder(Nodes.class);
153 NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
154 NodeKey nodeKey = new NodeKey(nodeId);
156 InstanceIdentifierBuilder<Node> nodeIdentifier = builderII
157 .<Node, NodeKey>child(Node.class, nodeKey);
159 InstanceIdentifier<Node> instance = nodeIdentifier.build();
161 flowRegistration.registerPath(NodeContext.class, instance);
163 RoutedRpcRegistration<SalFlowService> flowRegistration2 = getFlowRegistration();
165 return new AbstractObjectRegistration<OpenflowpluginTestServiceProvider>(this) {
167 protected void removeRegistration() {
168 flowRegistration2.close();