MD-SAL RuntimeDataProvider for Forwarding Rules
[controller.git] / opendaylight / md-sal / flow-management-compatibility / src / main / java / org / opendaylight / controller / md / frm / compatibility / FlowConfigMapping.xtend
1 package org.opendaylight.controller.md.frm.compatibility
2
3 import org.opendaylight.controller.forwardingrulesmanager.FlowConfig
4 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowBuilder
5
6 import static extension org.opendaylight.controller.sal.compability.NodeMapping.*
7 import static org.opendaylight.controller.sal.compability.MDFlowMapping.*
8 import static org.opendaylight.controller.sal.compability.ToSalConversionsUtils.*
9
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow
12 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem
14 import org.opendaylight.yangtools.yang.binding.Identifiable
15
16 class FlowConfigMapping {
17
18     static def toConfigurationFlow(FlowConfig sourceCfg) {
19         val it = new FlowBuilder();
20         val source = flowAdded(sourceCfg.flow);
21
22         action = source.action;
23         cookie = source.cookie;
24         hardTimeout = source.hardTimeout
25         idleTimeout = source.idleTimeout
26         match = source.match
27         node = source.node
28         key = new FlowKey(sourceCfg.name, node)
29         return it.build();
30     }
31
32     static def toFlowConfig(Flow sourceCfg) {
33         val flow = toFlow(sourceCfg);
34         val it = new FlowConfig;
35         name = sourceCfg.key.id
36         node = sourceCfg.node.toADNode();
37
38         return it
39     }
40
41     static def toFlowConfig(InstanceIdentifier<?> identifier) {
42         val it = new FlowConfig()
43         val FlowKey key = ((identifier.path.get(2) as IdentifiableItem<Flow,FlowKey>).key)
44         name = key.id;
45         node = key.node.toADNode();
46
47         return it;
48     }
49
50     static def boolean isFlowPath(InstanceIdentifier<?> path) {
51         if(path.path.size < 2) return false;
52         if (path.path.get(2) instanceof IdentifiableItem<?,?>) {
53             val IdentifiableItem<?,? extends Identifiable<?>> item = path.path.get(2) as IdentifiableItem<?,? extends Identifiable<?>>;
54             val Identifiable<?> key = item.key;
55             if (key instanceof FlowKey) {
56                 return true;
57             }
58         }
59         return false;
60     }
61 }