Merge "Drop Felix Gogo"
[openflowplugin.git] / applications / bulk-o-matic / src / main / java / org / opendaylight / openflowplugin / applications / bulk / o / matic / BulkOMaticUtils.java
1 /*
2  * Copyright (c) 2016 Ericsson 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.openflowplugin.applications.bulk.o.matic;
9
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30
31 public class BulkOMaticUtils {
32
33     private BulkOMaticUtils () { }
34
35     public static final int DEFUALT_STATUS = FlowCounter.OperationStatus.INIT.status();
36     public static final int DEFAULT_FLOW_COUNT = 0;
37     public static final long DEFAULT_COMPLETION_TIME = 0;
38     public static final String DEFAULT_UNITS = "ns";
39     public static final String DEVICE_TYPE_PREFIX = "openflow:";
40
41     public static String ipIntToStr (int k) {
42         return new StringBuilder().append(((k >> 24) & 0xFF)).append(".")
43                 .append(((k >> 16) & 0xFF)).append(".")
44                 .append(((k >> 8) & 0xFF)).append(".")
45                 .append((k & 0xFF)).append("/32").toString();
46     }
47
48     public static Match getMatch(final Integer sourceIp){
49         Ipv4Match ipv4Match = new Ipv4MatchBuilder().setIpv4Source(
50                 new Ipv4Prefix(ipIntToStr(sourceIp))).build();
51         MatchBuilder matchBuilder = new MatchBuilder();
52         matchBuilder.setLayer3Match(ipv4Match);
53         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
54         EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
55         ethTypeBuilder.setType(new EtherType(2048L));
56         ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
57         matchBuilder.setEthernetMatch(ethMatchBuilder.build());
58         return matchBuilder.build();
59     }
60
61     public static Flow buildFlow(Short tableId, String flowId, Match match){
62         FlowBuilder flowBuilder = new FlowBuilder();
63         flowBuilder.setKey(new FlowKey(new FlowId(flowId)));
64         flowBuilder.setTableId(tableId);
65         flowBuilder.setMatch(match);
66         return flowBuilder.build();
67     }
68
69     public static InstanceIdentifier<Flow> getFlowInstanceIdentifier(Short tableId, String flowId, String dpId) {
70         return InstanceIdentifier.create(Nodes.class).child(Node.class,
71                 new NodeKey(new NodeId(dpId)))
72                 .augmentation(FlowCapableNode.class)
73                 .child(Table.class, new TableKey(tableId))
74                 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow.class,
75                         new FlowKey(new FlowId(flowId)));
76     }
77
78     public static InstanceIdentifier<Node> getFlowCapableNodeId(String dpId){
79         return InstanceIdentifier.builder(Nodes.class)
80                 .child(Node.class, new NodeKey(new NodeId(dpId)))
81                 .build();
82     }
83
84     public static InstanceIdentifier<Table> getTableId(Short tableId, String dpId) {
85         return InstanceIdentifier.builder(Nodes.class)
86                 .child(Node.class, new NodeKey(new NodeId(dpId)))
87                 .augmentation(FlowCapableNode.class)
88                 .child(Table.class, new TableKey(tableId))
89                 .build();
90
91     }
92
93     public static InstanceIdentifier<Flow> getFlowId(final InstanceIdentifier<Table> tablePath, final String flowId) {
94         return tablePath.child(Flow.class, new FlowKey(new FlowId(flowId)));
95     }
96 }