@SuppressWarnings("unchecked") @Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(OFStatsRequest<REPLY> request) { ListenableFuture<List<REPLY>> ofStatsFuture = EasyMock.createNiceMock(ListenableFuture.class); // We create a mock future and return info from the map try { OFStatsType statsType = request.getStatsType(); List<REPLY> replies = (List<REPLY>) statsMap.get(statsType); EasyMock.expect(ofStatsFuture.get(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class))).andReturn(replies).anyTimes(); EasyMock.expect(ofStatsFuture.get()).andReturn(replies).anyTimes(); EasyMock.replay(ofStatsFuture); } catch (Exception e) { throw new RuntimeException(e); } return ofStatsFuture; }
/** Move the channel from scratch to WAIT_DESCRIPTION_STAT_REPLY state * Builds on moveToWaitConfigReply() * adds testing for WAIT_CONFIG_REPLY state */ @Test public void moveToWaitDescriptionStatReply() throws Exception { moveToWaitConfigReply(); connection.clearMessages(); OFGetConfigReply cr = factory.buildGetConfigReply() .setMissSendLen(0xFFFF) .build(); switchHandler.processOFMessage(cr); OFMessage msg = connection.retrieveMessage(); assertEquals(OFType.STATS_REQUEST, msg.getType()); OFStatsRequest<?> sr = (OFStatsRequest<?>)msg; assertEquals(OFStatsType.DESC, sr.getStatsType()); verifyUniqueXids(msg); assertThat(switchHandler.getStateForTesting(), CoreMatchers.instanceOf(OFSwitchHandshakeHandler.WaitDescriptionStatReplyState.class)); }
/** * Move the channel from scratch to WAIT_DESCRIPTION_STAT_REPLY state * Builds on moveToWaitConfigReply() * adds testing for WAIT_CONFIG_REPLY state */ @Test public void moveToWaitDescriptionStatReply() throws Exception { moveToWaitConfigReply(); resetChannel(); channel.write(capture(writeCapture)); expectLastCall().andReturn(null).atLeastOnce(); replay(channel); OFGetConfigReply cr = (OFGetConfigReply)buildOFMessage(OFType.GET_CONFIG_REPLY); sendMessageToHandlerWithControllerReset(Collections.<OFMessage>singletonList(cr)); List<OFMessage> msgs = getMessagesFromCapture(); assertEquals(1, msgs.size()); assertEquals(OFType.STATS_REQUEST, msgs.get(0).getType()); OFStatsRequest<?> sr = (OFStatsRequest<?>) msgs.get(0); assertEquals(OFStatsType.DESC, sr.getStatsType()); verifyUniqueXids(msgs); assertEquals(OFChannelHandler.ChannelState.WAIT_DESCRIPTION_STAT_REPLY, handler.getStateForTesting()); }
@Override public final void sendMsg(OFMessage m) { List<OFMessage> messages = new ArrayList<>(); messages.add(m); if (m.getType() == OFType.STATS_REQUEST) { OFStatsRequest sr = (OFStatsRequest) m; log.debug("OPLK ROADM rebuilding stats request type {}", sr.getStatsType()); switch (sr.getStatsType()) { case PORT: // add Oplink experiment message to get the port's current power messages.add(oplinkUtil.buildPortPowerRequest()); // add experiment message to get adjacent ports messages.add(oplinkUtil.buildPortAdjacencyRequest()); break; default: break; } } else { log.debug("OPLK ROADM sends msg:{}, as is", m.getType()); } super.sendMsg(messages); }
@Override public final void sendMsg(OFMessage m) { List<OFMessage> messages = new ArrayList<>(); messages.add(m); if (m.getType() == OFType.STATS_REQUEST) { OFStatsRequest sr = (OFStatsRequest) m; log.debug("OPLK Switch: Rebuilding stats request type {}", sr.getStatsType()); switch (sr.getStatsType()) { case PORT: //Send experiment status request for Optical Fiber switch to device //Note: We just re-use calient message for a short term. OFCalientPortStatsRequest portRequest = this.factory().buildCalientPortStatsRequest() .setXid(sr.getXid()) .setFlags(sr.getFlags()) .build(); messages.add(portRequest); break; default: break; } } else { log.debug("OPLK Switch: sends msg:{}, as is", m.getType()); } super.sendMsg(messages); }
@Override public final void sendMsg(OFMessage m) { List<OFMessage> messages = new ArrayList<>(); messages.add(m); if (m.getType() == OFType.STATS_REQUEST) { OFStatsRequest sr = (OFStatsRequest) m; log.debug("OPLK EDFA rebuilding stats request type {}", sr.getStatsType()); switch (sr.getStatsType()) { case PORT: // add Oplink experiment message to get the port's current power messages.add(oplinkUtil.buildPortPowerRequest()); // add experiment message to get adjacent ports messages.add(oplinkUtil.buildPortAdjacencyRequest()); break; default: break; } } else { log.debug("OPLK EDFA sends msg:{}, as is", m.getType()); } super.sendMsg(messages); }
@Override public final void sendMsg(OFMessage m) { OFMessage newMsg = m; if (m.getType() == OFType.STATS_REQUEST) { OFStatsRequest sr = (OFStatsRequest) m; log.debug("Rebuilding stats request type {}", sr.getStatsType()); switch (sr.getStatsType()) { case FLOW: OFCalientFlowStatsRequest request = this.factory().buildCalientFlowStatsRequest() .setCookie(((OFFlowStatsRequest) sr).getCookie()) .setCookieMask(((OFFlowStatsRequest) sr).getCookieMask()) .setMatch(this.factory().matchWildcardAll()) .setOutGroup(((OFFlowStatsRequest) sr).getOutGroup().getGroupNumber()) .setOutPort(OFPort.ANY) .setTableId(TableId.ALL) .setXid(sr.getXid()) .setFlags(sr.getFlags()) .build(); newMsg = request; break; case PORT: // TODO break; default: break; } } super.sendMsg(newMsg); }
protected Object getSwitchGroupStats(String switchId, OFStatsType statType, Integer groupId) { IFloodlightProviderService floodlightProvider = (IFloodlightProviderService) getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); IOFSwitch sw = floodlightProvider.getSwitches().get(HexString.toLong(switchId)); Future<List<OFStatsReply>> future; List<OFStatsReply> values = null; if (sw != null){ log.debug("Switch Group Stats: req sent for groupId {} " + "in switch {}",groupId, sw.getStringId()); OFStatsRequest<?> req = null; req = sw.getFactory().buildGroupStatsRequest().setXid (sw.getNextTransactionId()).setGroup(OFGroup.of(groupId)).build(); List<OFGroupStatsEntryMod> groupStats = new ArrayList<OFGroupStatsEntryMod>(); try { future = sw.getStatistics(req); values = future.get(10, TimeUnit.SECONDS); if(values.isEmpty()){ log.warn("group with groupId {} not found", groupId); return null; } for(OFStatsReply value : values){ for (OFGroupStatsEntry entry : ((OFGroupStatsReply)value).getEntries()) { OFGroupStatsEntryMod entryMod = new OFGroupStatsEntryMod(entry); groupStats.add(entryMod); } } log.debug("Switch Group Stats Entries from switch {} are {}", sw.getStringId(), groupStats); } catch (Exception e) { log.error("Failure retrieving statistics from switch " + sw, e); } return groupStats; } return null; }
@Override public Future<List<OFStatsReply>> getStatistics(OFStatsRequest<?> request) throws IOException { OFStatisticsFuture future = new OFStatisticsFuture(threadPool, this, (int) request.getXid()); log.info("description STAT REQUEST XID {}", request.getXid()); this.statsFutureMap.put((int) request.getXid(), future); this.channel.write(Collections.singletonList(request)); return future; }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(OFStatsRequest<REPLY> request) { return addInternalStatsReplyListener(connections.get(OFAuxId.MAIN).writeStatsRequest(request), request); }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(OFStatsRequest<REPLY> request, LogicalOFMessageCategory category) { return addInternalStatsReplyListener(getConnection(category).writeStatsRequest(request), request); }
/** * Append a listener to receive an OFStatsReply and update the * internal OFSwitch data structures. * * This presently taps into the following stats request * messages to listen for the corresponding reply: * -- OFTableFeaturesStatsRequest * * Extend this to tap into and update other OFStatsType messages. * * @param future * @param request * @return */ private <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> addInternalStatsReplyListener(final ListenableFuture<List<REPLY>> future, OFStatsRequest<REPLY> request) { switch (request.getStatsType()) { case TABLE_FEATURES: /* case YOUR_CASE_HERE */ future.addListener(new Runnable() { /* * We know the reply will be a list of OFStatsReply. */ @SuppressWarnings("unchecked") @Override public void run() { /* * The OFConnection handles REPLY_MORE for us in the case there * are multiple OFStatsReply messages with the same XID. */ try { List<? extends OFStatsReply> replies = future.get(); if (!replies.isEmpty()) { /* * By checking only the 0th element, we assume all others are the same type. * TODO If not, what then? */ switch (replies.get(0).getStatsType()) { case TABLE_FEATURES: processOFTableFeatures((List<OFTableFeaturesStatsReply>) future.get()); break; /* case YOUR_CASE_HERE */ default: throw new Exception("Received an invalid OFStatsReply of " + replies.get(0).getStatsType().toString() + ". Expected TABLE_FEATURES."); } } } catch (Exception e) { e.printStackTrace(); } } }, MoreExecutors.sameThreadExecutor()); /* No need for another thread. */ default: break; } return future; /* either unmodified or with an additional listener */ }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest( OFStatsRequest<REPLY> request) { if (!isConnected()) { return Futures.immediateFailedFuture(new SwitchDisconnectedException(getDatapathId())); } final DeliverableListenableFuture<List<REPLY>> future = new DeliverableListenableFuture<List<REPLY>>(); Deliverable<REPLY> deliverable = new Deliverable<REPLY>() { private final List<REPLY> results = Collections .synchronizedList(new ArrayList<REPLY>()); @Override public void deliver(REPLY reply) { results.add(reply); if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { // done future.deliver(results); } } @Override public void deliverError(Throwable cause) { future.deliverError(cause); } @Override public boolean isDone() { return future.isDone(); } @Override public boolean cancel(boolean mayInterruptIfRunning) { return future.cancel(mayInterruptIfRunning); } }; registerDeliverable(request.getXid(), deliverable); this.write(request); return future; }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest( OFStatsRequest<REPLY> request) { return Futures.immediateFailedFuture(new SwitchDisconnectedException(getDatapathId())); }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest( OFStatsRequest<REPLY> request) { // TODO Auto-generated method stub return null; }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest( OFStatsRequest<REPLY> request, LogicalOFMessageCategory category) { // TODO Auto-generated method stub return null; }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(OFStatsRequest<REPLY> request) { return null; }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(OFStatsRequest<REPLY> request) { return connections.get(OFAuxId.MAIN).writeStatsRequest(request); }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(OFStatsRequest<REPLY> request, LogicalOFMessageCategory category) { return getConnection(category).writeStatsRequest(request); }