7eafce1e9695eb6d9dae16a3bd0fa2d03dd6474c
[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.openflow.md.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 class FlowCreatorUtil {
23     
24     public static void setWildcardedFlowMatch(short version,MultipartRequestFlowBuilder flowBuilder){
25         if(version == OFConstants.OFP_VERSION_1_0){
26             flowBuilder.setMatchV10(createWildcardedMatchV10());
27         }
28         if(version == OFConstants.OFP_VERSION_1_3){
29             flowBuilder.setMatch(createWildcardedMatch());
30         }
31     }
32     
33     public static void setWildcardedFlowMatch(short version,MultipartRequestAggregateBuilder flowBuilder){
34         if(version == OFConstants.OFP_VERSION_1_0){
35             flowBuilder.setMatchV10(createWildcardedMatchV10());
36         }
37         if(version == OFConstants.OFP_VERSION_1_3){
38             flowBuilder.setMatch(createWildcardedMatch());
39         }
40     }
41
42     /**
43      * Method creates openflow 1.0 format match, that can match all the flow entries.
44      * @return
45      */
46     public static MatchV10 createWildcardedMatchV10() {
47         MatchV10Builder builder = new MatchV10Builder();
48         builder.setWildcards(new FlowWildcardsV10(true, true, true, true,
49                 true, true, true, true, true, true));
50         builder.setNwSrcMask((short) 0);
51         builder.setNwDstMask((short) 0);
52         builder.setInPort(0);
53         builder.setDlSrc(new MacAddress("00:00:00:00:00:00"));
54         builder.setDlDst(new MacAddress("00:00:00:00:00:00"));
55         builder.setDlVlan(0);
56         builder.setDlVlanPcp((short) 0);
57         builder.setDlType(0);
58         builder.setNwTos((short) 0);
59         builder.setNwProto((short) 0);
60         builder.setNwSrc(new Ipv4Address("0.0.0.0"));
61         builder.setNwDst(new Ipv4Address("0.0.0.0"));
62         builder.setTpSrc(0);
63         builder.setTpDst(0);
64         
65         return builder.build();
66     }
67     
68     public static Match createWildcardedMatch(){
69         return new MatchBuilder().setType(OxmMatchType.class).build();
70
71     }
72 }