Bug:129 Connection Manager Dashlet
[controller.git] / opendaylight / md-sal / compatibility / 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.compatibility.NodeMapping.*
7 import static org.opendaylight.controller.sal.compatibility.MDFlowMapping.*
8 import static org.opendaylight.controller.sal.compatibility.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 source = flowAdded(sourceCfg.flow);
20         val it = new FlowBuilder();
21         instructions = source.instructions;
22         cookie = source.cookie;
23         hardTimeout = source.hardTimeout
24         idleTimeout = source.idleTimeout
25         match = source.match
26         node = source.node
27         key = new FlowKey(sourceCfg.name,node);
28         return it.build();
29     }
30
31     static def toFlowConfig(Flow sourceCfg) {
32         val flow = toFlow(sourceCfg);
33         val it = new FlowConfig;
34         name = sourceCfg.key.id
35         node = sourceCfg.node.toADNode();
36
37         return it
38     }
39
40     static def toFlowConfig(InstanceIdentifier<?> identifier) {
41         val it = new FlowConfig()
42         val FlowKey key = ((identifier.path.get(2) as IdentifiableItem<Flow,FlowKey>).key)
43         name = key.id;
44         node = key.node.toADNode();
45
46         return it;
47     }
48
49     static def boolean isFlowPath(InstanceIdentifier<?> path) {
50         if(path.path.size < 2) return false;
51         if (path.path.get(2) instanceof IdentifiableItem<?,?>) {
52             val IdentifiableItem<?,? extends Identifiable<?>> item = path.path.get(2) as IdentifiableItem<?,? extends Identifiable<?>>;
53             val Identifiable<?> key = item.key;
54             if (key instanceof FlowKey) {
55                 return true;
56             }
57         }
58         return false;
59     }
60 }