2 * Copyright (c) 2016 Ericsson Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.applications.bulk.o.matic;
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.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;
31 public class BulkOMaticUtils {
33 public final static int DEFUALT_STATUS = FlowCounter.OperationStatus.INIT.status();
34 public final static int DEFAULT_FLOW_COUNT = 0;
35 public final static long DEFAULT_COMPLETION_TIME = 0;
36 public final static String DEFAULT_UNITS = "ns";
37 public final static String DEVICE_TYPE_PREFIX = "openflow:";
39 public static String ipIntToStr (int k) {
40 return new StringBuilder().append(((k >> 24) & 0xFF)).append(".")
41 .append(((k >> 16) & 0xFF)).append(".")
42 .append(((k >> 8) & 0xFF)).append(".")
43 .append((k & 0xFF)).append("/32").toString();
46 public static Match getMatch(final Integer sourceIp){
47 Ipv4Match ipv4Match = new Ipv4MatchBuilder().setIpv4Source(
48 new Ipv4Prefix(ipIntToStr(sourceIp))).build();
49 MatchBuilder matchBuilder = new MatchBuilder();
50 matchBuilder.setLayer3Match(ipv4Match);
51 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
52 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
53 ethTypeBuilder.setType(new EtherType(2048L));
54 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
55 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
56 return matchBuilder.build();
59 public static Flow buildFlow(Short tableId, String flowId, Match match){
60 FlowBuilder flowBuilder = new FlowBuilder();
61 flowBuilder.setKey(new FlowKey(new FlowId(flowId)));
62 flowBuilder.setTableId(tableId);
63 flowBuilder.setMatch(match);
64 return flowBuilder.build();
67 public static InstanceIdentifier<Flow> getFlowInstanceIdentifier(Short tableId, String flowId, String dpId) {
68 return InstanceIdentifier.create(Nodes.class).child(Node.class,
69 new NodeKey(new NodeId(dpId)))
70 .augmentation(FlowCapableNode.class)
71 .child(Table.class, new TableKey(tableId))
72 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow.class,
73 new FlowKey(new FlowId(flowId)));
76 public static InstanceIdentifier<Node> getFlowCapableNodeId(String dpId){
77 return InstanceIdentifier.builder(Nodes.class)
78 .child(Node.class, new NodeKey(new NodeId(dpId)))
82 public static InstanceIdentifier<Table> getTableId(Short tableId, String dpId) {
83 return InstanceIdentifier.builder(Nodes.class)
84 .child(Node.class, new NodeKey(new NodeId(dpId)))
85 .augmentation(FlowCapableNode.class)
86 .child(Table.class, new TableKey(tableId))
91 public static InstanceIdentifier<Flow> getFlowId(final InstanceIdentifier<Table> tablePath, final String flowId) {
92 return tablePath.child(Flow.class, new FlowKey(new FlowId(flowId)));