Added range type to subject-feature-definition/parameter
[groupbasedpolicy.git] / groupbasedpolicy / 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.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;
25
26 /**
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.
30  * @author readams
31  */
32 public abstract class OfTable {
33     protected static final Logger LOG =
34             LoggerFactory.getLogger(OfTable.class);
35
36     protected final OfTableCtx ctx;
37
38     public OfTable(OfTableCtx ctx) {
39         super();
40         this.ctx = ctx;
41     }
42
43     /**
44      * The context needed for flow tables
45      */
46     public static class OfTableCtx {
47         protected final DataBroker dataBroker;
48         protected final RpcProviderRegistry rpcRegistry;
49     
50         protected final PolicyManager policyManager;
51         protected final SwitchManager switchManager;
52         protected final EndpointManager epManager;
53     
54         protected final PolicyResolver policyResolver;
55     
56         protected final ScheduledExecutorService executor;
57     
58         public OfTableCtx(DataBroker dataBroker,
59                           RpcProviderRegistry rpcRegistry,
60                           PolicyManager policyManager,
61                           PolicyResolver policyResolver,
62                           SwitchManager switchManager,
63                           EndpointManager endpointManager,
64                           ScheduledExecutorService executor) {
65             super();
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;
73         }
74     
75     }
76
77     // *******
78     // OfTable
79     // *******
80
81     /**
82      * Update the relevant flow table for the node
83      * @param nodeId the node to update
84      * @param dirty the dirty set
85      * @throws Exception
86      */
87     public abstract void update(NodeId nodeId, 
88                                 PolicyInfo policyInfo,
89                                 Dirty dirty) throws Exception;
90     
91     // ***************
92     // Utility methods
93     // ***************
94
95     /**
96      * Parse an OF port number from a node connector ID
97      * @param id the ID
98      * @return the port number
99      */
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));
106     }
107 }