@Override public void processOFTableFeatures(List<OFTableFeaturesStatsReply> replies) { /* * Parse out all the individual replies for each table. */ for (OFTableFeaturesStatsReply reply : replies) { /* * Add or update the features for a particular table. */ List<OFTableFeatures> tfs = reply.getEntries(); for (OFTableFeatures tf : tfs) { tableFeaturesByTableId.put(tf.getTableId(), TableFeatures.of(tf)); tables.add(tf.getTableId()); log.trace("Received TableFeatures for TableId {}, TableName {}", tf.getTableId().toString(), tf.getName()); } } }
@Override /** * Accumulate a list of the OFTableFeaturesStatsReply's until there * are no more remaining. Then, pass the list to the switch for * parsing and configuration. * * The assumption is that the OFMessage dispatcher will call this each * time, which it does. We don't loop and receive here. * * @param m, The potential OFTableFeaturesStatsReply message we want to include */ void processOFStatsReply(OFStatsReply m) { if (m.getStatsType() == OFStatsType.TABLE_FEATURES) { replies.add((OFTableFeaturesStatsReply) m); if (!((OFTableFeaturesStatsReply)m).getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { handleTableFeaturesMessage(replies, false); nextState(); } } else { /* should only receive TABLE_FEATURES here */ log.error("Received {} message but expected TABLE_FEATURES.", m.getStatsType().toString()); } }
@SuppressWarnings("unchecked") public void handleTableFeatures(boolean subHandShakeComplete) throws Exception { // build the table features stats reply OFTableFeaturesStatsReply tf = createTableFeaturesStatsReply(); reset(sw); sw.startDriverHandshake(); expectLastCall().once(); expect(sw.isDriverHandshakeComplete()).andReturn(subHandShakeComplete).once(); sw.processOFTableFeatures(anyObject(List.class)); expectLastCall().once(); expect(sw.getOFFactory()).andReturn(factory).anyTimes(); replay(sw); switchHandler.processOFMessage(tf); }
protected OFTableFeaturesStatsReply createTableFeaturesStatsReply() { OFTableFeaturesStatsReply statsReply = factory.buildTableFeaturesStatsReply() .setEntries(Collections.singletonList(factory.buildTableFeatures() .setConfig(0) .setMaxEntries(100) .setMetadataMatch(U64.NO_MASK) .setMetadataWrite(U64.NO_MASK) .setName("MyTable") .setTableId(TableId.of(1)) .setProperties(Collections.singletonList((OFTableFeatureProp)factory.buildTableFeaturePropMatch() .setOxmIds(Collections.singletonList(U32.of(100))) .build()) ).build() ) ).build(); return statsReply; }
@Override public void processOFTableFeatures(List<OFTableFeaturesStatsReply> replies) { /* * Parse out all the individual replies for each table. */ for (OFTableFeaturesStatsReply reply : replies) { /* * Add or update the features for a particular table. */ List<OFTableFeatures> tfs = reply.getEntries(); for (OFTableFeatures tf : tfs) { tableFeaturesByTableId.put(tf.getTableId(), TableFeatures.of(tf)); log.trace("Received TableFeatures for TableId {}, TableName {}", tf.getTableId().toString(), tf.getName()); } } }
public void handleTableFeatures(boolean subHandShakeComplete) throws Exception { // build the table features stats reply OFTableFeaturesStatsReply tf = createTableFeaturesStatsReply(); reset(sw); sw.startDriverHandshake(); expectLastCall().once(); expect(sw.isDriverHandshakeComplete()).andReturn(subHandShakeComplete).once(); sw.processOFTableFeatures(anyObject(List.class)); expectLastCall().once(); expect(sw.getOFFactory()).andReturn(factory).anyTimes(); replay(sw); switchHandler.processOFMessage(tf); }
/** * 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 */ }
WaitTableFeaturesReplyState() { super(false); replies = new ArrayList<OFTableFeaturesStatsReply>(); }