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.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.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;
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}
60 public void setDataService(final DataBroker dataService) {
61 this.dataService = dataService;
65 * get flow registration
67 * @return {@link #flowRegistration}
69 public RoutedRpcRegistration<SalFlowService> getFlowRegistration() {
70 return flowRegistration;
74 * set {@link #flowRegistration}
76 * @param flowRegistration
78 public void setFlowRegistration(
79 final RoutedRpcRegistration<SalFlowService> flowRegistration) {
80 this.flowRegistration = flowRegistration;
84 * get notification service
86 * @return {@link #notificationProviderService}
88 public NotificationProviderService getNotificationService() {
89 return notificationProviderService;
93 * set {@link #notificationProviderService}
95 * @param notificationProviderService
97 public void setNotificationService(
98 final NotificationProviderService notificationProviderService) {
99 this.notificationProviderService = notificationProviderService;
102 public void start() {
103 OpenflowpluginTestServiceProvider.LOG
104 .info("SalFlowServiceProvider Started.");
110 * @see java.lang.AutoCloseable#close()
113 public void close() throws Exception {
114 OpenflowpluginTestServiceProvider.LOG
115 .info("SalFlowServiceProvide stopped.");
116 flowRegistration.close();
123 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
125 * #addFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.
126 * service.rev130819.AddFlowInput)
129 public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
130 String plus = ("addFlow - " + input);
131 OpenflowpluginTestServiceProvider.LOG.info(plus);
139 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
141 * #removeFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
142 * .service.rev130819.RemoveFlowInput)
145 public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
146 String plus = ("removeFlow - " + input);
147 OpenflowpluginTestServiceProvider.LOG.info(plus);
155 * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
157 * #updateFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
158 * .service.rev130819.UpdateFlowInput)
161 public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
162 String plus = ("updateFlow - " + input);
163 OpenflowpluginTestServiceProvider.LOG.info(plus);
169 * @return {@link CompositeObjectRegistrationBuilder #toInstance()}
171 public CompositeObjectRegistration<OpenflowpluginTestServiceProvider> register(
172 final ProviderContext ctx) {
173 CompositeObjectRegistrationBuilder<OpenflowpluginTestServiceProvider> builder = CompositeObjectRegistration
174 .<OpenflowpluginTestServiceProvider> builderFor(this);
176 RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation = ctx
177 .<SalFlowService> addRoutedRpcImplementation(
178 SalFlowService.class, this);
180 setFlowRegistration(addRoutedRpcImplementation);
182 InstanceIdentifierBuilder<Nodes> builderII = InstanceIdentifier
183 .<Nodes> builder(Nodes.class);
185 NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
186 NodeKey nodeKey = new NodeKey(nodeId);
188 InstanceIdentifierBuilder<Node> nodeIdentifier = builderII
189 .<Node, NodeKey> child(Node.class, nodeKey);
191 InstanceIdentifier<Node> instance = nodeIdentifier.build();
193 flowRegistration.registerPath(NodeContext.class, instance);
195 RoutedRpcRegistration<SalFlowService> flowRegistration2 = getFlowRegistration();
197 builder.add(flowRegistration2);
199 return builder.build();