+ Long port = null;
+
+ if (packetIn.getVersion() == OFConstants.OFP_VERSION_1_0 && packetIn.getInPort() != null) {
+ port = packetIn.getInPort().longValue();
+ } else if (packetIn.getVersion() == OFConstants.OFP_VERSION_1_3) {
+ if (packetIn.getMatch() != null && packetIn.getMatch().getMatchEntry() != null) {
+ List<MatchEntry> entries = packetIn.getMatch().getMatchEntry();
+
+ for (MatchEntry entry : entries) {
+ if (entry.getMatchEntryValue() instanceof InPortCase) {
+ InPortCase inPortCase = (InPortCase) entry.getMatchEntryValue();
+
+ InPort inPort = inPortCase.getInPort();
+
+ if (inPort != null) {
+ port = inPort.getPortNumber().getValue();
+ break;
+ }
+ }
+ }
+ }
+ }