OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestServiceProvider.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 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;
35
36 public class OpenflowpluginTestServiceProvider implements AutoCloseable,
37         SalFlowService {
38
39     private static final Logger LOG = LoggerFactory
40             .getLogger(OpenflowpluginTestServiceProvider.class);
41
42     private final DataBroker dataService;
43     private RoutedRpcRegistration<SalFlowService> flowRegistration;
44     private final NotificationProviderService notificationProviderService;
45
46     public OpenflowpluginTestServiceProvider(DataBroker dataService,
47             NotificationProviderService notificationProviderService) {
48         this.dataService = dataService;
49         this.notificationProviderService = notificationProviderService;
50     }
51
52     /**
53      * Get data service.
54      *
55      * @return {@link #dataService}
56      */
57     public DataBroker getDataService() {
58         return dataService;
59     }
60
61     /**
62      * Get flow registration.
63      *
64      * @return {@link #flowRegistration}
65      */
66     public RoutedRpcRegistration<SalFlowService> getFlowRegistration() {
67         return flowRegistration;
68     }
69
70     /**
71      * Set {@link #flowRegistration}.
72      */
73     public void setFlowRegistration(
74             final RoutedRpcRegistration<SalFlowService> flowRegistration) {
75         this.flowRegistration = flowRegistration;
76     }
77
78     /**
79      * Get notification service.
80      *
81      * @return {@link #notificationProviderService}
82      */
83     public NotificationProviderService getNotificationService() {
84         return notificationProviderService;
85     }
86
87     /*
88      * (non-Javadoc)
89      *
90      * @see java.lang.AutoCloseable#close()
91      */
92     @Override
93     public void close() throws Exception {
94         OpenflowpluginTestServiceProvider.LOG
95                 .info("SalFlowServiceProvide stopped.");
96         flowRegistration.close();
97     }
98
99     /*
100      * (non-Javadoc)
101      *
102      * @see
103      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
104      * SalFlowService
105      * #addFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.
106      * service.rev130819.AddFlowInput)
107      */
108     @Override
109     public ListenableFuture<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
110         OpenflowpluginTestServiceProvider.LOG.info("addFlow - {}", input);
111         return null;
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see
118      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
119      * SalFlowService
120      * #removeFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
121      * .service.rev130819.RemoveFlowInput)
122      */
123     @Override
124     public ListenableFuture<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
125         OpenflowpluginTestServiceProvider.LOG.info("removeFlow - {}", input);
126         return null;
127     }
128
129     /*
130      * (non-Javadoc)
131      *
132      * @see
133      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
134      * SalFlowService
135      * #updateFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
136      * .service.rev130819.UpdateFlowInput)
137      */
138     @Override
139     public ListenableFuture<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
140         OpenflowpluginTestServiceProvider.LOG.info("updateFlow - {}", input);
141         return null;
142     }
143
144     public ObjectRegistration<OpenflowpluginTestServiceProvider> register(RpcProviderRegistry rpcRegistry) {
145         RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation =
146                 rpcRegistry.addRoutedRpcImplementation(SalFlowService.class, this);
147
148         setFlowRegistration(addRoutedRpcImplementation);
149
150         InstanceIdentifierBuilder<Nodes> builderII = InstanceIdentifier
151                 .<Nodes>builder(Nodes.class);
152
153         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
154         NodeKey nodeKey = new NodeKey(nodeId);
155
156         InstanceIdentifierBuilder<Node> nodeIdentifier = builderII
157                 .<Node, NodeKey>child(Node.class, nodeKey);
158
159         InstanceIdentifier<Node> instance = nodeIdentifier.build();
160
161         flowRegistration.registerPath(NodeContext.class, instance);
162
163         RoutedRpcRegistration<SalFlowService> flowRegistration2 = getFlowRegistration();
164
165         return new AbstractObjectRegistration<OpenflowpluginTestServiceProvider>(this) {
166             @Override
167             protected void removeRegistration() {
168                 flowRegistration2.close();
169             }
170         };
171     }
172 }