alshabib | 1f44e8e | 2014-08-14 15:19:57 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.util; |
| 2 | |
| 3 | import java.util.Set; |
| 4 | |
| 5 | import com.google.common.collect.ImmutableSet; |
| 6 | |
| 7 | import org.projectfloodlight.openflow.types.U64; |
| 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; |
| 12 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 13 | import org.projectfloodlight.openflow.protocol.ver13.OFBsnPktinFlagSerializerVer13; |
| 14 | import org.projectfloodlight.openflow.types.OFMetadata; |
| 15 | |
| 16 | |
| 17 | public class MultiplePktInReasonUtil { |
| 18 | private MultiplePktInReasonUtil() {} |
| 19 | |
| 20 | /** |
| 21 | * This function is used in BVS T5/6 to decode the multiple packet in |
| 22 | * reasons in Match.MetaData field. |
| 23 | * */ |
| 24 | public static Set<OFBsnPktinFlag> getOFBsnPktinFlags(OFPacketIn pktIn) { |
| 25 | if(pktIn.getVersion() != OFVersion.OF_13) { |
| 26 | throw new IllegalArgumentException("multiple pkt in reasons are " |
| 27 | + "only supported by BVS using " |
| 28 | + "openflow 1.3"); |
| 29 | } |
| 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()); |
| 45 | } |
| 46 | } |