本文整理汇总了Java中org.openflow.protocol.OFStatisticsRequest.getLengthU方法的典型用法代码示例。如果您正苦于以下问题:Java OFStatisticsRequest.getLengthU方法的具体用法?Java OFStatisticsRequest.getLengthU怎么用?Java OFStatisticsRequest.getLengthU使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openflow.protocol.OFStatisticsRequest
的用法示例。
在下文中一共展示了OFStatisticsRequest.getLengthU方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFlows
import org.openflow.protocol.OFStatisticsRequest; //导入方法依赖的package包/类
/**
* @param sw
* the switch object that we wish to get flows from
* @param outPort
* the output action port we wish to find flows with
* @return a list of OFFlowStatisticsReply objects or essentially flows
*/
public List<OFFlowStatisticsReply> getFlows(IOFSwitch sw, Short outPort) {
statsReply = new ArrayList<OFFlowStatisticsReply>();
List<OFStatistics> values = null;
Future<List<OFStatistics>> future;
// Statistics request object for getting flows
OFStatisticsRequest req = new OFStatisticsRequest();
req.setStatisticType(OFStatisticsType.FLOW);
int requestLength = req.getLengthU();
OFFlowStatisticsRequest specificReq = new OFFlowStatisticsRequest();
specificReq.setMatch(new OFMatch().setWildcards(0xffffffff));
specificReq.setOutPort(outPort);
specificReq.setTableId((byte) 0xff);
req.setStatistics(Collections.singletonList((OFStatistics) specificReq));
requestLength += specificReq.getLength();
req.setLengthU(requestLength);
try {
// System.out.println(sw.getStatistics(req));
future = sw.queryStatistics(req);
values = future.get(10, TimeUnit.SECONDS);
if (values != null) {
for (OFStatistics stat : values) {
statsReply.add((OFFlowStatisticsReply) stat);
}
}
} catch (Exception e) {
log.error("Failure retrieving statistics from switch " + sw, e);
}
return statsReply;
}
示例2: getFlows
import org.openflow.protocol.OFStatisticsRequest; //导入方法依赖的package包/类
/**
* @param sw
* the switch object that we wish to get flows from
* @param outPort
* the output action port we wish to find flows with
* @return a list of OFFlowStatisticsReply objects or essentially flows
*/
public List<OFFlowStatisticsReply> getFlows(IOFSwitch sw, Short outPort) {
statsReply = new ArrayList<OFFlowStatisticsReply>();
List<OFStatistics> values = null;
Future<List<OFStatistics>> future;
// Statistics request object for getting flows
OFStatisticsRequest req = new OFStatisticsRequest();
req.setStatisticType(OFStatisticsType.FLOW);
int requestLength = req.getLengthU();
OFFlowStatisticsRequest specificReq = new OFFlowStatisticsRequest();
specificReq.setMatch(new OFMatch().setWildcards(0xffffffff));
specificReq.setOutPort(outPort);
specificReq.setTableId((byte) 0xff);
req.setStatistics(Collections.singletonList((OFStatistics) specificReq));
requestLength += specificReq.getLength();
req.setLengthU(requestLength);
try {
// System.out.println(sw.getStatistics(req));
future = sw.getStatistics(req);
values = future.get(10, TimeUnit.SECONDS);
if (values != null) {
for (OFStatistics stat : values) {
statsReply.add((OFFlowStatisticsReply) stat);
}
}
} catch (Exception e) {
log.error("Failure retrieving statistics from switch " + sw, e);
}
return statsReply;
}
示例3: getFlowStatsForSwitch
import org.openflow.protocol.OFStatisticsRequest; //导入方法依赖的package包/类
/**
* Retrieves FlowStats for everything on the switch
* and returns them.
* @param sw
* @return List of OFStatistics objects
*/
private List<OFStatistics> getFlowStatsForSwitch(IOFSwitch sw){
List <OFStatistics> statsReply = new ArrayList<OFStatistics>();
List <OFStatistics> values = null;
Future<List<OFStatistics>> future;
// Statistics request object for getting flows
OFStatisticsRequest req = new OFStatisticsRequest();
req.setStatisticType(OFStatisticsType.FLOW);
int requestLength = req.getLengthU();
OFFlowStatisticsRequest specificReq = new OFFlowStatisticsRequest();
specificReq.setMatch(new OFMatch().setWildcards(0xffffffff));
specificReq.setTableId((byte) 0xff);
specificReq.setOutPort((short)-1);
req.setStatistics(Collections.singletonList((OFStatistics)specificReq));
requestLength += specificReq.getLength();
req.setLengthU(requestLength);
try {
future = sw.queryStatistics(req);
log.debug(future.toString());
values = future.get(10, TimeUnit.SECONDS);
log.debug(values.toString());
if(values != null){
for(OFStatistics stat : values){
log.debug("Adding Stat");
statsReply.add(stat);
}
}
} catch (Exception e) {
log.error("Failure retrieving statistics from switch " + sw, e);
}
log.debug("Stats cached for switch: " + sw.getId() + ". Total flows cached: " + statsReply.size());
return statsReply;
}
示例4: getPortStatsForSwitch
import org.openflow.protocol.OFStatisticsRequest; //导入方法依赖的package包/类
private HashMap<Short, OFStatistics> getPortStatsForSwitch(IOFSwitch sw){
List <OFStatistics> values = null;
Future<List<OFStatistics>> future;
// Statistics request object for getting flows
OFStatisticsRequest req = new OFStatisticsRequest();
req.setStatisticType(OFStatisticsType.PORT);
int requestLength = req.getLengthU();
OFPortStatisticsRequest specificReq = new OFPortStatisticsRequest();
specificReq.setPortNumber(OFPort.OFPP_NONE.getValue());
req.setStatistics(Collections.singletonList((OFStatistics)specificReq));
requestLength += specificReq.getLength();
req.setLengthU(requestLength);
HashMap<Short, OFStatistics> statsReply = new HashMap<Short, OFStatistics>();
try {
future = sw.queryStatistics(req);
log.debug(future.toString());
values = future.get(10, TimeUnit.SECONDS);
log.debug(values.toString());
if(values != null){
for(OFStatistics stat : values){
OFPortStatisticsReply portStat = (OFPortStatisticsReply) stat;
log.debug("Adding Stat");
statsReply.put(portStat.getPortNumber(), stat);
}
}
} catch (Exception e) {
log.error("Failure retrieving statistics from switch " + sw, e);
}
log.debug("Stats cached for switch: " + sw.getId() + ". Total ports stats cached: " + statsReply.size());
return statsReply;
}
示例5: query
import org.openflow.protocol.OFStatisticsRequest; //导入方法依赖的package包/类
public ConcurrentMap<Long, List<OFStatistics>> query() {
Map<Long, Set<Link>> linkMap = linkDiscoveryService.getSwitchLinks();
for (Long switchId : linkMap.keySet()) {
// IOFSwitch sw = floodlightProvider.getSwitches().get(switchId);
IOFSwitch sw = floodlightProvider.getSwitch(switchId);
// System.out.println("sw = &&&&&&&&&&&&&&&&&&&" + switchId);
Future<List<OFStatistics>> future;
List<OFStatistics> values = null;
if (sw != null) {
OFStatisticsRequest req = new OFStatisticsRequest();
req.setStatisticType(OFStatisticsType.PORT);
OFPortStatisticsRequest specificReq = new OFPortStatisticsRequest();
specificReq.setPortNumber((short) OFPort.OFPP_NONE.getValue());
req.setStatistics(Collections
.singletonList((OFStatistics) specificReq));
int requestLength = req.getLengthU();
requestLength += specificReq.getLength();
req.setLengthU(requestLength);
try {
future = sw.queryStatistics(req);
values = future.get(10, TimeUnit.SECONDS);
// System.out
// .println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<get port statics info="
// + values);
if (ofstaticsMap.get(switchId) != null) {
preofstaticsMap.put(switchId,
ofstaticsMap.get(switchId));
}
ofstaticsMap.put(switchId, values);
// System.out
// .println("------------->>>>>>switchid<<<<<<--------------"
// + switchId + ofstaticsMap.get(switchId));
// System.out
// .println("------------->>>>>>switchid<<<<<<--------------"
// + switchId + values);
} catch (Exception e) {
log.error(
"Failure retrieving statistics from switch " + sw,
e);
}
}
}
return ofstaticsMap;
}
示例6: querySwitchStats
import org.openflow.protocol.OFStatisticsRequest; //导入方法依赖的package包/类
@LogMessageDoc(level="ERROR",
message="Failure to send stats request to switch {sw}, {exception}",
explanation="Controller is not able to send request to switch",
recommendation=LogMessageDoc.CHECK_SWITCH)
public void querySwitchStats(long swId,
IOFMessageListener callbackHandler) {
IOFSwitch sw = controllerProvider.getSwitches().get(swId);
if ((sw == null) || (!sw.isConnected())) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to send flow-stats request to switch Id {}",
swId);
}
return;
} else {
if (logger.isTraceEnabled()) {
logger.trace(
"Sending flow scan request to switch {} Id={}",
sw, swId);
}
}
OFStatisticsRequest req = new OFStatisticsRequest();
req.setStatisticType(OFStatisticsType.FLOW);
int requestLength = req.getLengthU();
OFFlowStatisticsRequest specificReq = new OFFlowStatisticsRequest();
OFMatch match = new OFMatch();
match.setWildcards(FlowCacheObj.WILD_ALL);
specificReq.setMatch(match);
specificReq.setOutPort(OFPort.OFPP_NONE.getValue());
specificReq.setTableId((byte) 0xff);
req.setStatistics(Collections.singletonList(
(OFStatistics)specificReq));
requestLength += specificReq.getLength();
req.setLengthU(requestLength);
try {
sw.sendStatsQuery(req, sw.getNextTransactionId(), callbackHandler);
} catch (Exception e) {
logger.error("Failure to send stats request to switch {}, {}",
sw, e);
}
}
示例7: getSwitchFlowsMatchOutputPort
import org.openflow.protocol.OFStatisticsRequest; //导入方法依赖的package包/类
/**
* Gets the flows from a switch that matches a given output port. This
* method is used to handle link down event.
* TODO - Refactor to use async response from switch
*
* @param sw the switch object
* @param outPort the output port of the switch to match
* @return the flows in the switch that match the output port
*/
@LogMessageDoc(level="ERROR",
message="Failure retrieving flows from switch {switch}, {exception}",
explanation="Controller is not able to retrieve flows from switch",
recommendation=LogMessageDoc.CHECK_SWITCH)
public void getSwitchFlowsMatchOutputPort(IOFSwitch sw, short outPort,
PendingSwitchResp pendQ) {
if (sw != null) {
OFStatisticsRequest req = new OFStatisticsRequest();
req.setStatisticType(OFStatisticsType.FLOW);
int requestLength = req.getLengthU();
OFFlowStatisticsRequest specificReq = new OFFlowStatisticsRequest();
OFMatch match = new OFMatch();
match.setWildcards(0xffffffff);
specificReq.setMatch(match);
specificReq.setOutPort(outPort);
specificReq.setTableId((byte) 0xff);
req.setStatistics(Collections.singletonList(
(OFStatistics)specificReq));
requestLength += specificReq.getLength();
req.setLengthU(requestLength);
try {
if (sw.isConnected()) {
int transId = sw.getNextTransactionId();
/* Need to add the pending resp. to the map before the
* request is sent to the switch; otherwise the response
* from the switch may come before it is added to map
* resulting in "unexpected" response.
*/
PendingSwRespKey pendSwRespKey =
new PendingSwRespKey(sw.getId(), transId);
pendSwRespMap.put(pendSwRespKey, pendQ);
if (logger.isTraceEnabled()) {
logger.trace("Added key {} to pending map",
pendSwRespKey.toString());
}
sw.sendStatsQuery(req, transId, this);
return;
}
} catch (Exception e) {
logger.error("Failure retrieving flows from switch {}, {}",
sw, e);
}
}
return;
}
示例8: testFlowCachePeriodicSwitchFlowTableScan
import org.openflow.protocol.OFStatisticsRequest; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test
public void testFlowCachePeriodicSwitchFlowTableScan() throws Exception {
betterFlowCacheMgr.fqTask.setEnableFlowQueryTask(true);
/* Periodic scan interval has already been set to low value
* in the setup() */
/* Add a flow to flow cache */
OFMatch ofm = new OFMatch();
ofm.setDataLayerSource(Ethernet.toByteArray(device1.getMACAddress()));
ofm.setDataLayerDestination(Ethernet.
toByteArray(device2.getMACAddress()));
ofm.setDataLayerVirtualLan((short)-1);
OFMatchWithSwDpid ofmWithSwDpid = new OFMatchWithSwDpid(ofm, 1L);
betterFlowCacheMgr.addFlow("testNetVirt1", ofmWithSwDpid, 2L, 1L, (short)1,
(short)0, FlowCacheObj.FCActionPERMIT);
/* Check that its scan count is zero */
FlowCacheObj fco =
betterFlowCacheMgr.getAllFlowsByApplInstVlanSrcDestDevicesInternal(
"testNetVirt1", (short)-1, device1.getMACAddress(),
device2.getMACAddress());
assertTrue(fco != null);
assertEquals(0, fco.fce.scanCnt);
Capture<OFStatisticsRequest> request =
new Capture<OFStatisticsRequest>(CaptureType.ALL);
Capture<Integer> xid = new Capture<Integer>(CaptureType.ALL);
Capture<IOFMessageListener> iofml =
new Capture<IOFMessageListener>(CaptureType.ALL);
OFStatisticsRequest req = new OFStatisticsRequest();
req.setStatisticType(OFStatisticsType.FLOW);
int requestLength = req.getLengthU();
OFFlowStatisticsRequest specificReq = new OFFlowStatisticsRequest();
OFMatch match = new OFMatch();
match.setWildcards(FlowCacheObj.WILD_ALL);
specificReq.setMatch(match);
specificReq.setOutPort(OFPort.OFPP_NONE.getValue());
specificReq.setTableId((byte) 0xff);
req.setStatistics(Collections.singletonList((OFStatistics)specificReq));
requestLength += specificReq.getLength();
req.setLengthU(requestLength);
sw1.sendStatsQuery(capture(request), capture(xid), capture(iofml));
expectLastCall().atLeastOnce();
sw2.sendStatsQuery(capture(request), capture(xid), capture(iofml));
expectLastCall().atLeastOnce();
sw3.sendStatsQuery(capture(request), capture(xid), capture(iofml));
expectLastCall().atLeastOnce();
replay(sw1, sw2, sw3);
/* Sleep for to allow for the switch flow table scans to kick in */
Thread.sleep((long)(betterFlowCacheMgr.periodicSwScanIntervalMsec*2.5));
verify(sw1, sw2, sw3);
assertTrue(iofml.getValues().size() >= 3);
assertEquals(betterFlowCacheMgr, iofml.getValues().get(1));
assertEquals(betterFlowCacheMgr, iofml.getValues().get(2));
assertEquals(betterFlowCacheMgr, iofml.getValues().get(3));
assertTrue(request.getValues().size() >= 3);
assertEquals(req, request.getValues().get(1));
assertEquals(req, request.getValues().get(2));
assertEquals(req, request.getValues().get(3));
/* Confirm that the scan count of the entry in flow cache was
* incremented as we didn't inject any response from the switches.
*/
assertTrue(2 <= fco.fce.scanCnt);
}