2 * Copyright (c) 2014 Cisco Systems, 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.groupbasedpolicy.renderer.ofoverlay.flow;
11 import java.util.concurrent.ScheduledExecutorService;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
15 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.EndpointManager;
16 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
17 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.Dirty;
18 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.SwitchManager;
19 import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
20 import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Manage the state of a openflow table by reacting to any events and updating
28 * the table state. This is an abstract class that must be extended for
29 * each specific table being managed.
32 public abstract class OfTable {
33 protected static final Logger LOG =
34 LoggerFactory.getLogger(OfTable.class);
36 protected final OfTableCtx ctx;
38 public OfTable(OfTableCtx ctx) {
44 * The context needed for flow tables
46 public static class OfTableCtx {
47 protected final DataBroker dataBroker;
48 protected final RpcProviderRegistry rpcRegistry;
50 protected final PolicyManager policyManager;
51 protected final SwitchManager switchManager;
52 protected final EndpointManager epManager;
54 protected final PolicyResolver policyResolver;
56 protected final ScheduledExecutorService executor;
58 public OfTableCtx(DataBroker dataBroker,
59 RpcProviderRegistry rpcRegistry,
60 PolicyManager policyManager,
61 PolicyResolver policyResolver,
62 SwitchManager switchManager,
63 EndpointManager endpointManager,
64 ScheduledExecutorService executor) {
66 this.dataBroker = dataBroker;
67 this.rpcRegistry = rpcRegistry;
68 this.policyManager = policyManager;
69 this.switchManager = switchManager;
70 this.epManager = endpointManager;
71 this.policyResolver = policyResolver;
72 this.executor = executor;
82 * Update the relevant flow table for the node
83 * @param nodeId the node to update
84 * @param dirty the dirty set
87 public abstract void update(NodeId nodeId,
88 PolicyInfo policyInfo,
89 Dirty dirty) throws Exception;
96 * Parse an OF port number from a node connector ID
98 * @return the port number
100 protected static long getOfPortNum(NodeConnectorId id) {
101 String cnid = id.getValue();
102 int ci = cnid.lastIndexOf(':');
103 if (ci < 0 || (ci+1 >= cnid.length()))
104 throw new NumberFormatException("Invalid node connector ID " + cnid);
105 return Long.parseLong(cnid.substring(ci+1));