ec67835b82f8cc184188086fb601c415ed959000
[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 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;
35
36 public class OpenflowpluginTestServiceProvider implements AutoCloseable,
37         SalFlowService {
38
39     private static final Logger LOG = LoggerFactory
40             .getLogger(OpenflowpluginTestServiceProvider.class);
41
42     private DataBroker dataService;
43     private RoutedRpcRegistration<SalFlowService> flowRegistration;
44     private NotificationProviderService notificationProviderService;
45
46     /**
47      * get data service
48      *
49      * @return {@link #dataService}
50      */
51     public DataBroker getDataService() {
52         return dataService;
53     }
54
55     /**
56      * set {@link #dataService}
57      *
58      * @param dataService
59      */
60     public void setDataService(final DataBroker dataService) {
61         this.dataService = dataService;
62     }
63
64     /**
65      * get flow registration
66      *
67      * @return {@link #flowRegistration}
68      */
69     public RoutedRpcRegistration<SalFlowService> getFlowRegistration() {
70         return flowRegistration;
71     }
72
73     /**
74      * set {@link #flowRegistration}
75      *
76      * @param flowRegistration
77      */
78     public void setFlowRegistration(
79             final RoutedRpcRegistration<SalFlowService> flowRegistration) {
80         this.flowRegistration = flowRegistration;
81     }
82
83     /**
84      * get notification service
85      *
86      * @return {@link #notificationProviderService}
87      */
88     public NotificationProviderService getNotificationService() {
89         return notificationProviderService;
90     }
91
92     /**
93      * set {@link #notificationProviderService}
94      *
95      * @param notificationProviderService
96      */
97     public void setNotificationService(
98             final NotificationProviderService notificationProviderService) {
99         this.notificationProviderService = notificationProviderService;
100     }
101
102     public void start() {
103         OpenflowpluginTestServiceProvider.LOG
104                 .info("SalFlowServiceProvider Started.");
105     }
106
107     /*
108      * (non-Javadoc)
109      *
110      * @see java.lang.AutoCloseable#close()
111      */
112     @Override
113     public void close() throws Exception {
114         OpenflowpluginTestServiceProvider.LOG
115                 .info("SalFlowServiceProvide stopped.");
116         flowRegistration.close();
117     }
118
119     /*
120      * (non-Javadoc)
121      *
122      * @see
123      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
124      * SalFlowService
125      * #addFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.
126      * service.rev130819.AddFlowInput)
127      */
128     @Override
129     public Future<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
130         String plus = ("addFlow - " + input);
131         OpenflowpluginTestServiceProvider.LOG.info(plus);
132         return null;
133     }
134
135     /*
136      * (non-Javadoc)
137      *
138      * @see
139      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
140      * SalFlowService
141      * #removeFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
142      * .service.rev130819.RemoveFlowInput)
143      */
144     @Override
145     public Future<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
146         String plus = ("removeFlow - " + input);
147         OpenflowpluginTestServiceProvider.LOG.info(plus);
148         return null;
149     }
150
151     /*
152      * (non-Javadoc)
153      *
154      * @see
155      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
156      * SalFlowService
157      * #updateFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
158      * .service.rev130819.UpdateFlowInput)
159      */
160     @Override
161     public Future<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
162         String plus = ("updateFlow - " + input);
163         OpenflowpluginTestServiceProvider.LOG.info(plus);
164         return null;
165     }
166
167     /**
168      * @param ctx
169      * @return {@link CompositeObjectRegistrationBuilder #toInstance()}
170      */
171     public CompositeObjectRegistration<OpenflowpluginTestServiceProvider> register(
172             final ProviderContext ctx) {
173         CompositeObjectRegistrationBuilder<OpenflowpluginTestServiceProvider> builder = CompositeObjectRegistration
174                 .<OpenflowpluginTestServiceProvider> builderFor(this);
175
176         RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation = ctx
177                 .<SalFlowService> addRoutedRpcImplementation(
178                         SalFlowService.class, this);
179
180         setFlowRegistration(addRoutedRpcImplementation);
181
182         InstanceIdentifierBuilder<Nodes> builderII = InstanceIdentifier
183                 .<Nodes> builder(Nodes.class);
184
185         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
186         NodeKey nodeKey = new NodeKey(nodeId);
187
188         InstanceIdentifierBuilder<Node> nodeIdentifier = builderII
189                 .<Node, NodeKey> child(Node.class, nodeKey);
190
191         InstanceIdentifier<Node> instance = nodeIdentifier.build();
192
193         flowRegistration.registerPath(NodeContext.class, instance);
194
195         RoutedRpcRegistration<SalFlowService> flowRegistration2 = getFlowRegistration();
196
197         builder.add(flowRegistration2);
198
199         return builder.build();
200     }
201 }