261a29cba84971be666fea8b31dc847cca1acbf3
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTableFeaturesTestServiceProvider.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.sal.binding.api.BindingAwareBroker.ProviderContext;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
14 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
23 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
24 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration.CompositeObjectRegistrationBuilder;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class OpenflowpluginTableFeaturesTestServiceProvider implements
32         AutoCloseable, SalTableService {
33
34     private static final Logger LOG = LoggerFactory
35             .getLogger(OpenflowpluginTableFeaturesTestServiceProvider.class);
36     private RoutedRpcRegistration<SalTableService> tableRegistration;
37     private NotificationProviderService notificationService;
38
39     /**
40      * get table registration
41      *
42      * @return {@link #tableRegistration}
43      */
44     public RoutedRpcRegistration<SalTableService> getTableRegistration() {
45         return this.tableRegistration;
46     }
47
48     /**
49      * set {@link #tableRegistration}
50      *
51      * @param tableRegistration
52      */
53     public void setTableRegistration(
54             final RoutedRpcRegistration<SalTableService> tableRegistration) {
55         this.tableRegistration = tableRegistration;
56     }
57
58     /**
59      * get notification service
60      *
61      * @return {@link #notificationService}
62      */
63     public NotificationProviderService getNotificationService() {
64         return this.notificationService;
65     }
66
67     /**
68      * set {@link #notificationService}
69      *
70      * @param notificationService
71      */
72     public void setNotificationService(
73             final NotificationProviderService notificationService) {
74         this.notificationService = notificationService;
75     }
76
77     public void start() {
78         OpenflowpluginTableFeaturesTestServiceProvider.LOG
79                 .info("SalTableServiceProvider Started.");
80     }
81
82     /*
83      * (non-Javadoc)
84      *
85      * @see java.lang.AutoCloseable#close()
86      */
87     @Override
88     public void close() throws Exception {
89         OpenflowpluginTableFeaturesTestServiceProvider.LOG
90                 .info("SalTableServiceProvider stopped.");
91         tableRegistration.close();
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see
98      * org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026
99      * .SalTableService
100      * #updateTable(org.opendaylight.yang.gen.v1.urn.opendaylight
101      * .table.service.rev131026.UpdateTableInput)
102      */
103     @Override
104     public Future<RpcResult<UpdateTableOutput>> updateTable(
105             UpdateTableInput input) {
106         String plus = ("updateTable - " + input);
107         OpenflowpluginTableFeaturesTestServiceProvider.LOG.info(plus);
108         return null;
109     }
110
111     /**
112      * @param ctx
113      * @return {@link CompositeObjectRegistrationBuilder #toInstance()}
114      */
115     public CompositeObjectRegistration<OpenflowpluginTableFeaturesTestServiceProvider> register(
116             final ProviderContext ctx) {
117         CompositeObjectRegistrationBuilder<OpenflowpluginTableFeaturesTestServiceProvider> builder = CompositeObjectRegistration
118                 .<OpenflowpluginTableFeaturesTestServiceProvider> builderFor(this);
119
120         RoutedRpcRegistration<SalTableService> addRoutedRpcImplementation = ctx
121                 .<SalTableService> addRoutedRpcImplementation(
122                         SalTableService.class, this);
123
124         setTableRegistration(addRoutedRpcImplementation);
125
126         InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier
127                 .<Nodes> builder(Nodes.class);
128
129         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
130         NodeKey nodeKey = new NodeKey(nodeId);
131
132         InstanceIdentifierBuilder<Node> nodeIndentifier = builder1
133                 .<Node, NodeKey> child(Node.class, nodeKey);
134
135         InstanceIdentifier<Node> instance = nodeIndentifier.build();
136
137         tableRegistration.registerPath(NodeContext.class, instance);
138
139         RoutedRpcRegistration<SalTableService> tableRegistration1 = this
140                 .getTableRegistration();
141
142         builder.add(tableRegistration1);
143
144         return builder.build();
145     }
146
147 }