Merge "Marked OpenstackGBP API Deprecated, cleaned up minor todos at same time, ready...
[groupbasedpolicy.git] / renderers / ofoverlay / src / main / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / flow / OfTable.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
10
11 import java.util.concurrent.ScheduledExecutorService;
12
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.OfContext;
17 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager;
18 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.Dirty;
19 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.SwitchManager;
20 import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
21 import org.opendaylight.groupbasedpolicy.resolver.PolicyResolver;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * Manage the state of a openflow  table by reacting to any events and updating
29  * the table state.  This is an abstract class that must be extended for
30  * each specific table being managed.
31  * @author readams
32  */
33 public abstract class OfTable {
34     protected static final Logger LOG =
35             LoggerFactory.getLogger(OfTable.class);
36
37     protected final OfContext ctx;
38
39     public OfTable(OfContext ctx) {
40         super();
41         this.ctx = ctx;
42     }
43
44
45     // *******
46     // OfTable
47     // *******
48
49     /**
50      * Update the relevant flow table for the node
51      * @param nodeId the node to update
52      * @param dirty the dirty set
53      * @throws Exception
54      */
55     public abstract void update(NodeId nodeId, 
56                                 PolicyInfo policyInfo,
57                                 Dirty dirty) throws Exception;
58     
59     // ***************
60     // Utility methods
61     // ***************
62
63     /**
64      * Parse an OF port number from a node connector ID
65      * @param id the ID
66      * @return the port number
67      */
68     protected static long getOfPortNum(NodeConnectorId id) {
69         String cnid = id.getValue();
70         int ci = cnid.lastIndexOf(':');
71         if (ci < 0 || (ci+1 >= cnid.length()))
72             throw new NumberFormatException("Invalid node connector ID " + cnid);
73         return Long.parseLong(cnid.substring(ci+1));
74     }
75 }