From 7ef5ca6c5cd3bbfeaaee11e54c0f9fbf824f0463 Mon Sep 17 00:00:00 2001 From: Anilkumar Vishnoi Date: Sat, 25 Jan 2014 17:42:55 +0530 Subject: [PATCH] Minor fix in Ip address decoding from flow stats. If user specify 32 as a mask, as per specs switch ignores it. And when you fetch the flow stats switch, it returns null as a mask value. I added a check for it and now I am explicitly adding 32 as a mask if ip mask value in flow statistics is null" Added code to send group/meter statistics request only to openflow 1.3+ switches. Change-Id: I10b23f058f42d60338d51319c0f5545501e22838 Signed-off-by: Anilkumar Vishnoi --- .../md/core/sal/ModelDrivenSwitchImpl.java | 100 ++++++++++++++---- .../convertor/match/MatchConvertorImpl.java | 15 ++- 2 files changed, 96 insertions(+), 19 deletions(-) diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java index fd3145a74e..29d63c6420 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/ModelDrivenSwitchImpl.java @@ -743,6 +743,16 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getAllGroupStatistics(GetAllGroupStatisticsInput input) { + GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); + + if(version == OFConstants.OFP_VERSION_1_0){ + output.setTransactionId(null); + output.setGroupStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } //Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); @@ -770,11 +780,9 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetAllGroupStatisticsOutputBuilder output = new GetAllGroupStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setGroupStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); @@ -783,6 +791,16 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getGroupDescription(GetGroupDescriptionInput input) { + GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder(); + Collection errors = Collections.emptyList(); + + if(version == OFConstants.OFP_VERSION_1_0){ + output.setTransactionId(null); + output.setGroupDescStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } //Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); @@ -807,11 +825,9 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetGroupDescriptionOutputBuilder output = new GetGroupDescriptionOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setGroupDescStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); @@ -820,6 +836,15 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getGroupFeatures(GetGroupFeaturesInput input) { + GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder(); + Collection errors = Collections.emptyList(); + + if(version == OFConstants.OFP_VERSION_1_0){ + output.setTransactionId(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } //Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); @@ -844,10 +869,8 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetGroupFeaturesOutputBuilder output = new GetGroupFeaturesOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @@ -855,6 +878,16 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getGroupStatistics(GetGroupStatisticsInput input) { + GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); + + if(version == OFConstants.OFP_VERSION_1_0){ + output.setTransactionId(null); + output.setGroupStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } //Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); @@ -882,11 +915,9 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetGroupStatisticsOutputBuilder output = new GetGroupStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setGroupStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @@ -895,6 +926,17 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { public Future> getAllMeterConfigStatistics( GetAllMeterConfigStatisticsInput input) { + GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); + + if(version == OFConstants.OFP_VERSION_1_0){ + output.setTransactionId(null); + output.setMeterConfigStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + + } //Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); @@ -922,11 +964,9 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetAllMeterConfigStatisticsOutputBuilder output = new GetAllMeterConfigStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setMeterConfigStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @@ -934,6 +974,16 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getAllMeterStatistics(GetAllMeterStatisticsInput input) { + GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); + + if(version == OFConstants.OFP_VERSION_1_0){ + output.setTransactionId(null); + output.setMeterStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } //Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); @@ -961,11 +1011,9 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetAllMeterStatisticsOutputBuilder output = new GetAllMeterStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setMeterStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @@ -973,6 +1021,15 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { @Override public Future> getMeterFeatures(GetMeterFeaturesInput input) { + GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder(); + Collection errors = Collections.emptyList(); + + if(version == OFConstants.OFP_VERSION_1_0){ + output.setTransactionId(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + } //Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); @@ -997,16 +1054,26 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetMeterFeaturesOutputBuilder output = new GetMeterFeaturesOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @Override public Future> getMeterStatistics(GetMeterStatisticsInput input) { + + GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder(); + Collection errors = Collections.emptyList(); + + if(version == OFConstants.OFP_VERSION_1_0){ + output.setTransactionId(null); + output.setMeterStats(null); + + RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); + return Futures.immediateFuture(rpcResult); + + } //Generate xid to associate it with the request Long xid = this.getSessionContext().getNextXid(); @@ -1035,11 +1102,9 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // Prepare rpc return output. Set xid and send it back. LOG.debug("Return results and transaction id back to caller"); - GetMeterStatisticsOutputBuilder output = new GetMeterStatisticsOutputBuilder(); output.setTransactionId(generateTransactionId(xid)); output.setMeterStats(null); - Collection errors = Collections.emptyList(); RpcResult rpcResult = Rpcs.getRpcResult(true, output.build(), errors); return Futures.immediateFuture(rpcResult); } @@ -1132,8 +1197,7 @@ public class ModelDrivenSwitchImpl extends AbstractModelDrivenSwitch { // TODO Auto-generated method stub return null; } - - + @Override public Future> updatePort(UpdatePortInput input) { PortModInput ofPortModInput = null ; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java index 4fb538b8d5..860a2ef1fc 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java @@ -695,7 +695,20 @@ public class MatchConvertorImpl implements MatchConvertor> { String ipv4PrefixStr = ipv4AddressMatchEntry.getIpv4Address().getValue(); MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class); if (maskMatchEntry != null) { - ipv4PrefixStr += PREFIX_SEPARATOR + ByteBuffer.wrap(maskMatchEntry.getMask()).getInt(); + int receivedMask = ByteBuffer.wrap(maskMatchEntry.getMask()).getInt(); + int shiftCount=0; + while(receivedMask != 0xffffffff){ + receivedMask = receivedMask >> 1; + shiftCount++; + } + ipv4PrefixStr += PREFIX_SEPARATOR + (32-shiftCount); + }else{ + //Openflow Spec : 1.3.2 + //An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask. + // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow + // statistics response. + + ipv4PrefixStr+=PREFIX_SEPARATOR + "32"; } if (ofMatch.getOxmMatchField().equals(Ipv4Src.class)) { ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(ipv4PrefixStr)); -- 2.36.6