Bug 1588 - OFConstants.java moved to openflowplugin-api module
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / util / FlowCreatorUtil.java
1 /**
2  * Copyright IBM Corporation, 2013.  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.openflow.md.util;
9
10 import org.opendaylight.openflowplugin.api.OFConstants;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10Builder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
21
22 public final class FlowCreatorUtil {
23
24     private FlowCreatorUtil() {
25         throw new AssertionError("FlowCreatorUtil is not expected to be instantiated.");
26     }
27
28     public static void setWildcardedFlowMatch(short version, MultipartRequestFlowBuilder flowBuilder) {
29         if (version == OFConstants.OFP_VERSION_1_0) {
30             flowBuilder.setMatchV10(createWildcardedMatchV10());
31         }
32         if (version == OFConstants.OFP_VERSION_1_3) {
33             flowBuilder.setMatch(createWildcardedMatch());
34         }
35     }
36
37     public static void setWildcardedFlowMatch(short version, MultipartRequestAggregateBuilder aggregateBuilder) {
38         if (version == OFConstants.OFP_VERSION_1_0) {
39             aggregateBuilder.setMatchV10(createWildcardedMatchV10());
40         }
41         if (version == OFConstants.OFP_VERSION_1_3) {
42             aggregateBuilder.setMatch(createWildcardedMatch());
43         }
44     }
45
46     /**
47      * Method creates openflow 1.0 format match, that can match all the flow entries.
48      *
49      * @return
50      */
51     public static MatchV10 createWildcardedMatchV10() {
52         MatchV10Builder builder = new MatchV10Builder();
53         builder.setWildcards(new FlowWildcardsV10(true, true, true, true,
54                 true, true, true, true, true, true));
55         builder.setNwSrcMask((short) 0);
56         builder.setNwDstMask((short) 0);
57         builder.setInPort(0);
58         builder.setDlSrc(new MacAddress("00:00:00:00:00:00"));
59         builder.setDlDst(new MacAddress("00:00:00:00:00:00"));
60         builder.setDlVlan(0);
61         builder.setDlVlanPcp((short) 0);
62         builder.setDlType(0);
63         builder.setNwTos((short) 0);
64         builder.setNwProto((short) 0);
65         builder.setNwSrc(new Ipv4Address("0.0.0.0"));
66         builder.setNwDst(new Ipv4Address("0.0.0.0"));
67         builder.setTpSrc(0);
68         builder.setTpDst(0);
69         return builder.build();
70     }
71
72     public static Match createWildcardedMatch() {
73         return new MatchBuilder().setType(OxmMatchType.class).build();
74     }
75 }