本文整理汇总了Java中org.openflow.protocol.statistics.OFPortStatisticsRequest类的典型用法代码示例。如果您正苦于以下问题:Java OFPortStatisticsRequest类的具体用法?Java OFPortStatisticsRequest怎么用?Java OFPortStatisticsRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OFPortStatisticsRequest类属于org.openflow.protocol.statistics包,在下文中一共展示了OFPortStatisticsRequest类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPortStatsForSwitch
import org.openflow.protocol.statistics.OFPortStatisticsRequest; //导入依赖的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;
}
示例2: query
import org.openflow.protocol.statistics.OFPortStatisticsRequest; //导入依赖的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;
}
示例3: getStatistics
import org.openflow.protocol.statistics.OFPortStatisticsRequest; //导入依赖的package包/类
@Override
public synchronized Future<List<OFStatistics>> getStatistics(OFStatisticsRequest request) throws IOException {
if (request == null) {
throw new UnsupportedOperationException("Not supported.");
}
if (request.getStatisticType() == null
|| !request.getStatisticType().equals(OFStatisticsType.PORT)) {
throw new UnsupportedOperationException("Not supported.");
}
if (request.getStatistics() == null
|| request.getStatistics().size() != 1) {
throw new UnsupportedOperationException("Not supported.");
}
if (!request.getStatistics().get(0).getClass()
.equals(OFPortStatisticsRequest.class)) {
throw new UnsupportedOperationException("Not supported.");
}
final short port = ((OFPortStatisticsRequest) request.getStatistics()
.get(0)).getPortNumber();
return new Future<List<OFStatistics>>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public List<OFStatistics> get() throws InterruptedException, ExecutionException {
OFPortStatisticsReply reply = new OFPortStatisticsReply();
reply.setTransmitBytes(traffic.get(port));
List<OFStatistics> result = new ArrayList<>();
result.add(reply);
return result;
}
@Override
public List<OFStatistics> get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException,
TimeoutException {
return get();
}
};
}
示例4: portReplyBuilder
import org.openflow.protocol.statistics.OFPortStatisticsRequest; //导入依赖的package包/类
/**
* PortReplyBuilder for the OF_STATISTICS_PORT_REQUEST
*
* @param portRequest the incoming portRequest
* @return the List of OfPortStatsReplies
*/
private List<OFPortStatisticsReply> portReplyBuilder(OFPortStatisticsRequest portRequest) {
List<OFPortStatisticsReply> replyList = new ArrayList<>();
if (portRequest.getPortNumber() != OFPort.OFPP_NONE.getValue()) {
OFPortStatisticsReply portReply = new OFPortStatisticsReply();
portReply.setPortNumber(portRequest.getPortNumber());
if (this.randomizeFlag) {
portReply.setCollisions(randomInt());
portReply.setReceiveBytes(randomInt());
portReply.setReceiveCRCErrors(randomInt());
portReply.setReceiveDropped(randomInt());
portReply.setreceiveErrors(randomInt());
portReply.setReceiveFrameErrors(randomInt());
portReply.setReceiveOverrunErrors(randomInt());
portReply.setreceivePackets(randomInt());
portReply.setTransmitBytes(randomInt());
portReply.setTransmitDropped(randomInt());
portReply.setTransmitErrors(randomInt());
portReply.setTransmitPackets(randomInt());
} else {
portReply.setCollisions(42);
portReply.setReceiveBytes(42);
portReply.setReceiveCRCErrors(42);
portReply.setReceiveDropped(42);
portReply.setreceiveErrors(42);
portReply.setReceiveFrameErrors(42);
portReply.setReceiveOverrunErrors(42);
portReply.setreceivePackets(42);
portReply.setTransmitBytes(42);
portReply.setTransmitDropped(42);
portReply.setTransmitErrors(42);
portReply.setTransmitPackets(42);
}
replyList.add(portReply);
} else {
for (int i = 1; i <= this.config.getSwitchConfig().getPortCountperSwitch(); i++) {
replyList.addAll(
portReplyBuilder(
(new OFPortStatisticsRequest()).setPortNumber((short) i)
)
);
}
}
return replyList;
}
示例5: handlePortStatsRequest
import org.openflow.protocol.statistics.OFPortStatisticsRequest; //导入依赖的package包/类
private void handlePortStatsRequest(OFMessage msg){
OFStatisticsRequest request = (OFStatisticsRequest) msg;
OFPortStatisticsRequest specificRequest = (OFPortStatisticsRequest) request.getFirstStatistics();
List<OFStatistics> statsReply = new ArrayList<OFStatistics>();
int length = 0;
if(specificRequest.getPortNumber() != OFPort.OFPP_NONE.getValue()){
OFStatistics myStat = this.parent.getPortStats(mySwitch.getId(), specificRequest.getPortNumber());
if(myStat != null){
statsReply.add(myStat);
length += myStat.getLength();
}else{
return;
}
}else{
HashMap<Short, OFStatistics> allPortStats = this.parent.getPortStats(mySwitch.getId());
if(allPortStats != null){
Iterator<Entry<Short, OFStatistics>> it = allPortStats.entrySet().iterator();
while(it.hasNext()){
Entry<Short, OFStatistics> entry = it.next();
length += entry.getValue().getLength();
statsReply.add(entry.getValue());
}
}else{
return;
}
}
OFStatisticsReply reply = new OFStatisticsReply();
reply.setStatisticType(OFStatisticsType.PORT);
reply.setStatistics(statsReply);
reply.setXid(msg.getXid());
reply.setFlags((short)0x0000);
reply.setLengthU(length + reply.getLength());
try {
ofcch.sendMessage(reply);
} catch (IOException e1) {
e1.printStackTrace();
}
return;
}