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