xinwu | d6a402f | 2014-04-22 15:43:58 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.util; |
| 2 | |
| 3 | import java.util.Set; |
| 4 | |
xinwu | 29274d7 | 2014-04-22 19:20:19 -0700 | [diff] [blame] | 5 | import com.google.common.collect.ImmutableSet; |
| 6 | |
| 7 | import org.projectfloodlight.openflow.types.U64; |
xinwu | d6a402f | 2014-04-22 15:43:58 -0700 | [diff] [blame] | 8 | import org.projectfloodlight.openflow.protocol.OFBsnPktinFlag; |
| 9 | import org.projectfloodlight.openflow.protocol.OFPacketIn; |
| 10 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 11 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
xinwu | 29274d7 | 2014-04-22 19:20:19 -0700 | [diff] [blame] | 12 | import org.projectfloodlight.openflow.protocol.match.Match; |
xinwu | d6a402f | 2014-04-22 15:43:58 -0700 | [diff] [blame] | 13 | import org.projectfloodlight.openflow.protocol.ver13.OFBsnPktinFlagSerializerVer13; |
| 14 | import org.projectfloodlight.openflow.types.OFMetadata; |
| 15 | |
xinwu | 29274d7 | 2014-04-22 19:20:19 -0700 | [diff] [blame] | 16 | |
xinwu | d6a402f | 2014-04-22 15:43:58 -0700 | [diff] [blame] | 17 | public class MultiplePktInReasonUtil { |
| 18 | private MultiplePktInReasonUtil() {} |
| 19 | |
xinwu | 29274d7 | 2014-04-22 19:20:19 -0700 | [diff] [blame] | 20 | /** |
| 21 | * This function is used in BVS T5/6 to decode the multiple packet in |
| 22 | * reasons in Match.MetaData field. |
| 23 | * */ |
xinwu | d6a402f | 2014-04-22 15:43:58 -0700 | [diff] [blame] | 24 | public static Set<OFBsnPktinFlag> getOFBsnPktinFlags(OFPacketIn pktIn) { |
Vishnu Emmadi | cf53bb9 | 2014-12-06 12:17:13 -0800 | [diff] [blame^] | 25 | if(pktIn.getVersion().compareTo(OFVersion.OF_13) < 0) { |
xinwu | d6a402f | 2014-04-22 15:43:58 -0700 | [diff] [blame] | 26 | throw new IllegalArgumentException("multiple pkt in reasons are " |
| 27 | + "only supported by BVS using " |
Vishnu Emmadi | cf53bb9 | 2014-12-06 12:17:13 -0800 | [diff] [blame^] | 28 | + "openflow version >= 1.3"); |
xinwu | d6a402f | 2014-04-22 15:43:58 -0700 | [diff] [blame] | 29 | } |
xinwu | 29274d7 | 2014-04-22 19:20:19 -0700 | [diff] [blame] | 30 | |
| 31 | Match match = pktIn.getMatch(); |
| 32 | if(match == null) { |
| 33 | return ImmutableSet.<OFBsnPktinFlag>of(); |
| 34 | } |
| 35 | OFMetadata metaData = match.get(MatchField.METADATA); |
| 36 | if(metaData == null) { |
| 37 | return ImmutableSet.<OFBsnPktinFlag>of(); |
| 38 | } |
| 39 | U64 metaDataValue = metaData.getValue(); |
| 40 | if(metaDataValue == null) { |
| 41 | return ImmutableSet.<OFBsnPktinFlag>of(); |
| 42 | } |
| 43 | return OFBsnPktinFlagSerializerVer13.ofWireValue(metaDataValue |
| 44 | .getValue()); |
xinwu | d6a402f | 2014-04-22 15:43:58 -0700 | [diff] [blame] | 45 | } |
| 46 | } |