2 * Copyright (c) 2016, 2017 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.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;
31 public final class BulkOMaticUtils {
33 public static final int DEFUALT_STATUS = FlowCounter.OperationStatus.INIT.status();
34 public static final int DEFAULT_FLOW_COUNT = 0;
35 public static final int DEFAULT_TABLE_COUNT = 0;
36 public static final long DEFAULT_COMPLETION_TIME = 0;
37 public static final String DEFAULT_UNITS = "ns";
38 public static final String DEVICE_TYPE_PREFIX = "openflow:";
40 private BulkOMaticUtils() {
43 public static String ipIntToStr(int number) {
44 return new StringBuilder().append(number >> 24 & 0xFF).append(".")
45 .append(number >> 16 & 0xFF).append(".")
46 .append(number >> 8 & 0xFF).append(".")
47 .append(number & 0xFF).append("/32").toString();
50 public static Match getMatch(final int sourceIp) {
51 Ipv4Match ipv4Match = new Ipv4MatchBuilder().setIpv4Source(new Ipv4Prefix(ipIntToStr(sourceIp))).build();
52 MatchBuilder matchBuilder = new MatchBuilder();
53 matchBuilder.setLayer3Match(ipv4Match);
54 EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
55 EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
56 ethTypeBuilder.setType(new EtherType(2048L));
57 ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
58 matchBuilder.setEthernetMatch(ethMatchBuilder.build());
59 return matchBuilder.build();
62 public static Flow buildFlow(Short tableId, String flowId, Match match) {
63 FlowBuilder flowBuilder = new FlowBuilder();
64 flowBuilder.setKey(new FlowKey(new FlowId(flowId)));
65 flowBuilder.setTableId(tableId);
66 flowBuilder.setMatch(match);
67 return flowBuilder.build();
70 public static InstanceIdentifier<Flow> getFlowInstanceIdentifier(Short tableId, String flowId, String dpId) {
71 return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(dpId)))
72 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId))
73 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow.class,
74 new FlowKey(new FlowId(flowId)));
77 public static InstanceIdentifier<Node> getFlowCapableNodeId(String dpId) {
78 return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(dpId))).build();
81 public static InstanceIdentifier<Table> getTableId(Short tableId, String dpId) {
82 return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(dpId)))
83 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).build();
86 public static InstanceIdentifier<Flow> getFlowId(final InstanceIdentifier<Table> tablePath, final String flowId) {
87 return tablePath.child(Flow.class, new FlowKey(new FlowId(flowId)));