2 * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.ovssfc;
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;
20 import java.util.List;
22 public class SfpHandler {
23 private static final Logger LOGGER = LoggerFactory.getLogger(SfpHandler.class);
24 private OvsSfcProvider ovsSfcProvider = OvsSfcProvider.getOvsSfcProvider();
27 public int getVlan () {
31 public void setVlan (int vlan) {
35 void processSfp (SfcEvent.Action action, ServiceFunctionPath serviceFunctionPath) {
36 LOGGER.trace("\nOVSSFC Enter: {}, action: {}\n sfp: {}",
37 Thread.currentThread().getStackTrace()[1],
39 serviceFunctionPath.toString());
44 sfpUpdate(serviceFunctionPath);
52 LOGGER.trace("\nOVSSFC Exit: {}", Thread.currentThread().getStackTrace()[1]);
55 void processSfps (SfcEvent.Action action, ServiceFunctionPaths serviceFunctionPaths) {
56 LOGGER.trace("\nOVSSFC Enter: {}, action: {}\n sfps: {}",
57 Thread.currentThread().getStackTrace()[1],
59 serviceFunctionPaths.toString());
71 LOGGER.trace("\nOVSSFC Exit: {}", Thread.currentThread().getStackTrace()[1]);
75 * Get the ingress ssf. This sff will take the ingress acl flows.
77 * Get the system-id from the sff to find the ovs node.
81 private void sfpUpdate (ServiceFunctionPath serviceFunctionPath) {
82 LOGGER.trace("\nOVSSFC {}\n Building SFP {}",
83 Thread.currentThread().getStackTrace()[1],
84 serviceFunctionPath.getName());
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
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);
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);
110 if (servicePathHop.getServiceIndex().equals(startingIndex)) {
111 ovsSfcProvider.flows.initializeFlowRules(dpid);
112 // Add ingress classifier rule
113 ovsSfcProvider.flows.writeIngressAcl(dpid, 0L, 0, true);
116 // Add t30 classifier reg rule
117 // Add t31 nextHop rule