MD-SAL Statistics Manager - Implemented rpc/notifications for individual flow statistics
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / AbstractModelDrivenSwitch.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 package org.opendaylight.openflowplugin.openflow.md.core.sal;
9
10 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
12 import org.opendaylight.openflowplugin.openflow.md.ModelDrivenSwitch;
13 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
23 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
24 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration.CompositeObjectRegistrationBuilder;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26
27 /**
28  * RPC abstract for MD-switch
29  */
30 public abstract class AbstractModelDrivenSwitch implements ModelDrivenSwitch {
31
32     private final InstanceIdentifier<Node> identifier;
33
34     private RoutedRpcRegistration<SalFlowService> flowRegistration;
35
36     private RoutedRpcRegistration<SalGroupService> groupRegistration;
37
38     private RoutedRpcRegistration<SalMeterService> meterRegistration;
39
40     private RoutedRpcRegistration<PacketProcessingService> packetRegistration;
41     
42     private RoutedRpcRegistration<OpendaylightFlowStatisticsService> flowStatisticsRegistration;
43
44     private RoutedRpcRegistration<OpendaylightGroupStatisticsService> groupStatisticsRegistration;
45
46     private RoutedRpcRegistration<OpendaylightMeterStatisticsService> meterStatisticsRegistration;
47
48     protected final SessionContext sessionContext;
49
50     protected AbstractModelDrivenSwitch(InstanceIdentifier<Node> identifier,SessionContext conductor) {
51         this.identifier = identifier;
52         this.sessionContext = conductor;
53     }
54
55     @Override
56     public final InstanceIdentifier<Node> getIdentifier() {
57         return this.identifier;
58     }
59
60     @Override
61     public CompositeObjectRegistration<ModelDrivenSwitch> register(ProviderContext ctx) {
62         CompositeObjectRegistrationBuilder<ModelDrivenSwitch> builder = CompositeObjectRegistration
63                 .<ModelDrivenSwitch> builderFor(this);
64
65         flowRegistration = ctx.addRoutedRpcImplementation(SalFlowService.class, this);
66         flowRegistration.registerPath(NodeContext.class, getIdentifier());
67         builder.add(flowRegistration);
68
69         meterRegistration = ctx.addRoutedRpcImplementation(SalMeterService.class, this);
70         meterRegistration.registerPath(NodeContext.class, getIdentifier());
71         builder.add(meterRegistration);
72
73         groupRegistration = ctx.addRoutedRpcImplementation(SalGroupService.class, this);
74         groupRegistration.registerPath(NodeContext.class, getIdentifier());
75         builder.add(groupRegistration);
76
77         packetRegistration = ctx.addRoutedRpcImplementation(PacketProcessingService.class, this);
78         packetRegistration.registerPath(NodeContext.class, getIdentifier());
79         builder.add(packetRegistration);
80
81         flowStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightFlowStatisticsService.class, this);
82         flowStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
83         builder.add(flowStatisticsRegistration);
84
85         groupStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightGroupStatisticsService.class, this);
86         groupStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
87         builder.add(groupStatisticsRegistration);
88
89         meterStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightMeterStatisticsService.class, this);
90         meterStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
91         builder.add(meterStatisticsRegistration);
92
93         return builder.toInstance();
94     }
95
96     /**
97      * @return session context 
98      */
99     public SessionContext getSessionContext() {
100         return sessionContext;
101     }
102
103 }