Fix for bug - 369
[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(Long.parseLong(sourceCfg.name),node);
28         return it.build();
29     }
30
31     static def toFlowConfig(Flow sourceCfg) {
32         val it = new FlowConfig;
33         name = String.valueOf(sourceCfg.id);
34         node = sourceCfg.node.toADNode();
35
36         return it
37     }
38
39     static def toFlowConfig(InstanceIdentifier<?> identifier) {
40         val it = new FlowConfig()
41         val FlowKey key = ((identifier.path.get(2) as IdentifiableItem<Flow,FlowKey>).key)
42         name = String.valueOf(key.id);
43         node = key.node.toADNode();
44
45         return it;
46     }
47
48     static def boolean isFlowPath(InstanceIdentifier<?> path) {
49         if(path.path.size < 2) return false;
50         if (path.path.get(2) instanceof IdentifiableItem<?,?>) {
51             val IdentifiableItem<?,? extends Identifiable<?>> item = path.path.get(2) as IdentifiableItem<?,? extends Identifiable<?>>;
52             val Identifiable<?> key = item.key;
53             if (key instanceof FlowKey) {
54                 return true;
55             }
56         }
57         return false;
58     }
59 }