c2c14c7a3bccf265a7655110a30ac614a56cf66c
[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 com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
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.AbstractObjectRegistration;
24 import org.opendaylight.yangtools.concepts.ObjectRegistration;
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     public void setTableRegistration(
52             final RoutedRpcRegistration<SalTableService> tableRegistration) {
53         this.tableRegistration = tableRegistration;
54     }
55
56     /**
57      * Get notification service.
58      *
59      * @return {@link #notificationService}
60      */
61     public NotificationProviderService getNotificationService() {
62         return this.notificationService;
63     }
64
65     /**
66      * Set {@link #notificationService}.
67      */
68     public void setNotificationService(
69             final NotificationProviderService notificationService) {
70         this.notificationService = notificationService;
71     }
72
73     public void start() {
74         OpenflowpluginTableFeaturesTestServiceProvider.LOG
75                 .info("SalTableServiceProvider Started.");
76     }
77
78     /*
79      * (non-Javadoc)
80      *
81      * @see java.lang.AutoCloseable#close()
82      */
83     @Override
84     public void close() throws Exception {
85         OpenflowpluginTableFeaturesTestServiceProvider.LOG
86                 .info("SalTableServiceProvider stopped.");
87         tableRegistration.close();
88     }
89
90     /*
91      * (non-Javadoc)
92      *
93      * @see
94      * org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026
95      * .SalTableService
96      * #updateTable(org.opendaylight.yang.gen.v1.urn.opendaylight
97      * .table.service.rev131026.UpdateTableInput)
98      */
99     @Override
100     public ListenableFuture<RpcResult<UpdateTableOutput>> updateTable(
101             UpdateTableInput input) {
102         OpenflowpluginTableFeaturesTestServiceProvider.LOG.info("updateTable - {}", input);
103         return null;
104     }
105
106     public ObjectRegistration<OpenflowpluginTableFeaturesTestServiceProvider> register(
107             final RpcProviderRegistry rpcRegistry) {
108         RoutedRpcRegistration<SalTableService> addRoutedRpcImplementation = rpcRegistry.addRoutedRpcImplementation(
109                         SalTableService.class, this);
110
111         setTableRegistration(addRoutedRpcImplementation);
112
113         InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier
114                 .<Nodes>builder(Nodes.class);
115
116         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
117         NodeKey nodeKey = new NodeKey(nodeId);
118
119         InstanceIdentifierBuilder<Node> nodeIndentifier = builder1
120                 .<Node, NodeKey>child(Node.class, nodeKey);
121
122         InstanceIdentifier<Node> instance = nodeIndentifier.build();
123
124         tableRegistration.registerPath(NodeContext.class, instance);
125
126         RoutedRpcRegistration<SalTableService> tableRegistration1 = this
127                 .getTableRegistration();
128
129         return new AbstractObjectRegistration<OpenflowpluginTableFeaturesTestServiceProvider>(this) {
130             @Override
131             protected void removeRegistration() {
132                 tableRegistration1.close();
133             }
134         };
135     }
136 }