619edee41dcc68cd7462c44ad292b4027fc5a2b1
[packetcable.git] / protocol_plugins.packetcable / src / main / java / org / opendaylight / controller / protocol_plugin / packetcable / internal / FlowProgrammerService.java
1 /*
2  @header@
3  */
4
5 package org.opendaylight.controller.protocol_plugin.packetcable.internal;
6
7 import org.opendaylight.controller.sal.flowprogrammer.Flow;
8 import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
9 import org.opendaylight.controller.sal.core.Node;
10 import org.opendaylight.controller.sal.utils.Status;
11 import org.opendaylight.controller.sal.utils.StatusCode;
12
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 import org.umu.cops.prpdp.COPSPdpException;
17 import org.pcmm.gates.IPCMMGate;
18 import org.pcmm.PCMMDef;
19 import org.pcmm.PCMMGlobalConfig;
20 import org.pcmm.PCMMPdpMsgSender;
21 import org.pcmm.PCMMPdpDataProcess;
22 import org.pcmm.PCMMPdpAgent;
23
24
25
26 /**
27  * Represents the packetcable plugin component in charge of programming the flows
28  * the flow programming and relay them to functional modules above SAL.
29  */
30 public class FlowProgrammerService implements IPluginInFlowProgrammerService
31 {
32     protected PCMMPdpDataProcess process;
33     protected PCMMPdpAgent pcmm_pdp;
34     protected PCMMPdpMsgSender pcmm_sender;
35
36
37     protected static final Logger logger = LoggerFactory
38                                            .getLogger(FlowProgrammerService.class);
39     void init() {
40         logger.info("FlowProgrammerService: init");
41         pcmm_pdp = new PCMMPdpAgent(PCMMDef.C_PCMM, process);
42     }
43
44     /**
45      * Function called by the dependency manager when at least one dependency
46      * become unsatisfied or when the component is shutting down because for
47      * example bundle is being stopped.
48      *
49      */
50     void destroy() {
51         logger.info("FlowProgrammerService: destroy");
52     }
53
54     /**
55      * Function called by dependency manager after "init ()" is called and after
56      * the services provided by the class are registered in the service registry
57      *
58      */
59     void start() {
60         logger.info("FlowProgrammerService: start");
61         try  {
62             logger.info("Open connection to CMTS");
63             pcmm_pdp.connect( PCMMGlobalConfig.DefaultCMTS, 3918 );
64             pcmm_sender = new PCMMPdpMsgSender (PCMMDef.C_PCMM, pcmm_pdp.getClientHandle(), pcmm_pdp.getSocket());
65         } catch (Exception e) {
66             System.out.println(e.getMessage());
67         }
68     }
69
70     /**
71      * Function called by the dependency manager before the services exported by
72      * the component are unregistered, this will be followed by a "destroy ()"
73      * calls
74      *
75      */
76     void stop() {
77         logger.info("FlowProgrammerService: stop");
78     }
79
80
81     /**
82      * Synchronously add a flow to the network node
83      *
84      * @param node
85      * @param flow
86      */
87     public Status addFlow(Node node, Flow flow){
88         logger.info("FlowProgrammerService: addFlow");
89         FlowConverter fc = new FlowConverter(flow);
90         fc.dump();
91         IPCMMGate gate = fc.getServiceFlow();
92         fc.dumpAction();
93         try {
94             logger.info("sendGateSet to CMTS");
95             pcmm_sender.sendGateSet(gate);
96         } catch (COPSPdpException e) {
97             logger.error("Failed to sendGateSet, reason: " + e.getMessage());
98             return new Status(StatusCode.INTERNALERROR, "Failed to sendGateSet to CMTS");
99         }
100         return new Status(StatusCode.SUCCESS);
101     }
102
103     /**
104      * Synchronously modify existing flow on the switch
105      *
106      * @param node
107      * @param flow
108      */
109     public Status modifyFlow(Node node, Flow oldFlow, Flow newFlow){
110         logger.info("FlowProgrammerService: modifyFlow");
111         return new Status(StatusCode.SUCCESS);
112     }
113     /**
114      * Synchronously remove the flow from the network node
115      *
116      * @param node
117      * @param flow
118      */
119     public Status removeFlow(Node node, Flow flow){
120         logger.info("FlowProgrammerService: removeFlow");
121         logger.info("FlowProgrammerService: removeFlow GateID1 " + PCMMGlobalConfig.getGateID1() );
122         logger.info("FlowProgrammerService: removeFlow GateID2 " + PCMMGlobalConfig.getGateID2() );
123         logger.info("FlowProgrammerService: removeFlow FlowID " + flow.getId() );
124         if ( PCMMGlobalConfig.getGateID1()  != 0 ) {
125             logger.info("Remove Flow " + PCMMGlobalConfig.getGateID1() );
126             try {
127                 pcmm_sender.sendGateDelete( PCMMGlobalConfig.getGateID1() );
128             } catch (COPSPdpException e) {
129                 logger.error("Failed to sendGateDelete, reason: " + e.getMessage());
130                 return new Status(StatusCode.INTERNALERROR, "Failed to sendGateDelete to CMTS");
131             }
132         }
133         return new Status(StatusCode.SUCCESS);
134     }
135
136     /**
137      * Asynchronously add a flow to the network node
138      *
139      * @param node
140      * @param flow
141      * @param rid
142      */
143     public Status addFlowAsync(Node node, Flow flow, long rid){
144         logger.info("FlowProgrammerService: addFlowAsync");
145         return new Status(StatusCode.SUCCESS);
146     }
147
148     /**
149      * Asynchronously modify existing flow on the switch
150      *
151      * @param node
152      * @param flow
153      * @param rid
154      */
155     public Status modifyFlowAsync(Node node, Flow oldFlow, Flow newFlow, long rid){
156         logger.info("FlowProgrammerService: modifyFlowAsync");
157         return new Status(StatusCode.SUCCESS);
158     }
159
160     /**
161      * Asynchronously remove the flow from the network node
162      *
163      * @param node
164      * @param flow
165      * @param rid
166      */
167     public Status removeFlowAsync(Node node, Flow flow, long rid){
168         logger.info("FlowProgrammerService: removeFlowAsync");
169         return new Status(StatusCode.SUCCESS);
170     }
171
172     /**
173      * Remove all flows present on the network node
174      *
175      * @param node
176      */
177     public Status removeAllFlows(Node node){
178         logger.info("FlowProgrammerService: removeAllFlows");
179         return new Status(StatusCode.SUCCESS);
180     }
181
182     /**
183      * Send Barrier message synchronously. The caller will be blocked until the
184      * Barrier reply arrives.
185      *
186      * @param node
187      */
188     public Status syncSendBarrierMessage(Node node){
189         logger.info("FlowProgrammerService: syncSendBarrierMessage");
190         return new Status(StatusCode.SUCCESS);
191     }
192
193     /**
194      * Send Barrier message asynchronously. The caller is not blocked.
195      *
196      * @param node
197      */
198     public Status asyncSendBarrierMessage(Node node){
199         logger.info("FlowProgrammerService: asyncSendBarrierMessage");
200         return new Status(StatusCode.SUCCESS);
201     }
202   }