Remove commons/parent bundle
[netvirt.git] / ovs-sfc / src / main / java / org / opendaylight / ovsdb / ovssfc / SfpHandler.java
1 /*
2  * Copyright (c) 2014, 2015 Red Hat, 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.ovsdb.ovssfc;
10
11 import org.opendaylight.controller.sal.core.Node;
12 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarder;
13 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.ServiceFunctionPaths;
14 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath;
15 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.service.function.path.ServicePathHop;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.acl.rev140520.access.lists.access.list.AccessListEntries;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 import java.util.List;
21
22 public class SfpHandler {
23     private static final Logger LOGGER = LoggerFactory.getLogger(SfpHandler.class);
24     private OvsSfcProvider ovsSfcProvider = OvsSfcProvider.getOvsSfcProvider();
25     private int vlan;
26
27     public int getVlan () {
28         return vlan;
29     }
30
31     public void setVlan (int vlan) {
32         this.vlan = vlan;
33     }
34
35     void processSfp (SfcEvent.Action action, ServiceFunctionPath serviceFunctionPath) {
36         LOGGER.trace("\nOVSSFC Enter: {}, action: {}\n   sfp: {}",
37                 Thread.currentThread().getStackTrace()[1],
38                 action.toString(),
39                 serviceFunctionPath.toString());
40
41         switch (action) {
42             case CREATE:
43             case UPDATE:
44                 sfpUpdate(serviceFunctionPath);
45                 break;
46             case DELETE:
47                 break;
48             default:
49                 break;
50         }
51
52         LOGGER.trace("\nOVSSFC Exit: {}", Thread.currentThread().getStackTrace()[1]);
53     }
54
55     void processSfps (SfcEvent.Action action, ServiceFunctionPaths serviceFunctionPaths) {
56         LOGGER.trace("\nOVSSFC Enter: {}, action: {}\n   sfps: {}",
57                 Thread.currentThread().getStackTrace()[1],
58                 action.toString(),
59                 serviceFunctionPaths.toString());
60
61         switch (action) {
62         case CREATE:
63         case UPDATE:
64             break;
65         case DELETE:
66             break;
67         default:
68             break;
69         }
70
71         LOGGER.trace("\nOVSSFC Exit: {}", Thread.currentThread().getStackTrace()[1]);
72     }
73
74     /*
75      * Get the ingress ssf. This sff will take the ingress acl flows.
76      * Get the acl.
77      * Get the system-id from the sff to find the ovs node.
78      * Program flows.
79      *
80      */
81     private void sfpUpdate (ServiceFunctionPath serviceFunctionPath) {
82         LOGGER.trace("\nOVSSFC {}\n Building SFP {}",
83                 Thread.currentThread().getStackTrace()[1],
84                 serviceFunctionPath.getName());
85
86         // TODO: replace with correct getAccessList when the restonf issue is fixed.
87         //ovsSfcProvider.aclUtils.getAccessList(serviceFunctionPath.getName());
88         AccessListEntries accessListEntries = null;
89         LOGGER.trace("\n   acl: {}", accessListEntries);
90         // TODO: code to convert acl into flows
91
92         String serviceFunctionForwarderName;
93         ServiceFunctionForwarder serviceFunctionForwarder = null;
94         Short startingIndex = serviceFunctionPath.getStartingIndex();
95         List<ServicePathHop> servicePathHopList = serviceFunctionPath.getServicePathHop();
96         for (ServicePathHop servicePathHop : servicePathHopList) {
97             LOGGER.trace("\n   sph: {}", servicePathHop);
98
99             serviceFunctionForwarderName = servicePathHop.getServiceFunctionForwarder();
100             serviceFunctionForwarder = ovsSfcProvider.sffUtils.readServiceFunctionForwarder(serviceFunctionForwarderName);
101             if (serviceFunctionForwarder != null) {
102                 String systemId = ovsSfcProvider.sffUtils.getSystemId(serviceFunctionForwarder);
103                 Node ovsNode = ovsSfcProvider.ovsUtils.getNodeFromSystemId(systemId);
104                 if (ovsNode != null) {
105                     Long dpid = ovsSfcProvider.ovsUtils.getDpid(ovsNode, serviceFunctionForwarderName);
106                     if (dpid.equals(0)) {
107                         LOGGER.warn("cannot find dpid for {}", serviceFunctionForwarderName);
108                         continue;
109                     }
110                     if (servicePathHop.getServiceIndex().equals(startingIndex)) {
111                         ovsSfcProvider.flows.initializeFlowRules(dpid);
112                         // Add ingress classifier rule
113                         ovsSfcProvider.flows.writeIngressAcl(dpid, 0L, 0, true);
114                         // Add vlan t0 rule
115                     }
116                     // Add t30 classifier reg rule
117                     // Add t31 nextHop rule
118                 }
119             }
120         }
121     }
122
123 }