@Override public void run() { if (sw.getRole() == RoleState.MASTER) { log.trace("Collecting stats for {}", sw.getStringId()); OFTableStatsRequest request = sw.factory().buildTableStatsRequest() .build(); sw.sendMsg(request); } } }
private void ofFlowStatsRequestAllSend() { OFFlowStatsRequest request = sw.factory().buildFlowStatsRequest() .setMatch(sw.factory().matchWildcardAll()) .setTableId(TableId.ALL) .setOutPort(OFPort.NO_MASK) .build(); synchronized (this) { // set the request xid to check the reply in OpenFlowRuleProvider // After processing the reply of this request message, // this must be set to NO_FLOW_MISSING_XID(-1) by provider setFlowMissingXid(request.getXid()); log.debug("ofFlowStatsRequestAllSend: request={}, dpid={}", request.toString(), sw.getStringId()); sw.sendMsg(request); } }
@Override public void run() { if (sw.getRole() == RoleState.MASTER) { log.trace("Collecting stats for {}", sw.getStringId()); OFFlowStatsRequest request = sw.factory().buildFlowStatsRequest() .setMatch(sw.factory().matchWildcardAll()) .setTableId(TableId.ALL) .setOutPort(OFPort.NO_MASK) .build(); sw.sendMsg(request); } } }
private OFPacketOut packetOut(OpenFlowSwitch sw, byte[] eth, OFPort out) { OFPacketOut.Builder builder = sw.factory().buildPacketOut(); OFAction act = sw.factory().actions() .buildOutput() .setPort(out) .build(); return builder .setBufferId(OFBufferId.NO_BUFFER) .setInPort(OFPort.CONTROLLER) .setActions(Collections.singletonList(act)) .setData(eth) .build(); }
/** * Sends port statistic request to switch. */ private void sendPortStatistic() { if (sw.getRole() != RoleState.MASTER) { return; } Long statsXid = xidAtomic.getAndIncrement(); OFPortStatsRequest statsRequest = sw.factory().buildPortStatsRequest() .setPortNo(OFPort.ANY) .setXid(statsXid) .build(); sw.sendMsg(statsRequest); }
private OFActionOutput buildOutput(Integer port) { OFActionOutput act = sw.factory().actions() .buildOutput() .setPort(OFPort.of(port)) .build(); return act; }
private void sendGroupStatistic() { if (log.isTraceEnabled()) { log.trace("sendGroupStatistics {}:{}", sw.getStringId(), sw.getRole()); } if (sw.getRole() != RoleState.MASTER) { return; } Long statsXid = OpenFlowGroupProvider.getXidAndAdd(2); OFGroupStatsRequest statsRequest = sw.factory().buildGroupStatsRequest() .setGroup(OFGroup.ALL) .setXid(statsXid) .build(); sw.sendMsg(statsRequest); Long descXid = statsXid + 1; OFGroupDescStatsRequest descStatsRequest = sw.factory().buildGroupDescStatsRequest() .setXid(descXid) .build(); sw.sendMsg(descStatsRequest); }
@Override public void build(OFPort outPort) { if (isBuilt.getAndSet(true)) { return; } OFPacketOut.Builder builder = sw.factory().buildPacketOut(); OFAction act = buildOutput(outPort.getPortNumber()); pktout = builder.setXid(pktin.getXid()) .setInPort(pktinInPort()) .setBufferId(OFBufferId.NO_BUFFER) .setData(pktin.getData()) // .setBufferId(pktin.getBufferId()) .setActions(Collections.singletonList(act)) .build(); }
@Override public void build(Ethernet ethFrame, OFPort outPort) { if (isBuilt.getAndSet(true)) { return; } OFPacketOut.Builder builder = sw.factory().buildPacketOut(); OFAction act = buildOutput(outPort.getPortNumber()); pktout = builder.setXid(pktin.getXid()) .setBufferId(OFBufferId.NO_BUFFER) .setInPort(pktinInPort()) .setActions(Collections.singletonList(act)) .setData(ethFrame.serialize()) .build(); }
private void removeRule(FlowRule flowRule) { Dpid dpid = Dpid.dpid(flowRule.deviceId().uri()); OpenFlowSwitch sw = controller.getSwitch(dpid); if (sw == null) { return; } FlowRuleExtPayLoad flowRuleExtPayLoad = flowRule.payLoad(); if (hasPayload(flowRuleExtPayLoad)) { OFMessage msg = new ThirdPartyMessage(flowRuleExtPayLoad.payLoad()); sw.sendMsg(msg); return; } sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), Optional.empty(), Optional.of(driverService)).buildFlowDel()); if (adaptiveFlowSampling) { // Remove TypedFlowEntry to deviceFlowEntries in NewAdaptiveFlowStatsCollector NewAdaptiveFlowStatsCollector collector = afsCollectors.get(dpid); if (collector != null) { collector.removeFlows(flowRule); } } }
@Override public void triggerProbe(DeviceId deviceId) { LOG.debug("Triggering probe on device {}", deviceId); final Dpid dpid = dpid(deviceId.uri()); OpenFlowSwitch sw = controller.getSwitch(dpid); if (sw == null || !sw.isConnected()) { LOG.error("Failed to probe device {} on sw={}", deviceId, sw); providerService.deviceDisconnected(deviceId); return; } else { LOG.trace("Confirmed device {} connection", deviceId); } // Prompt an update of port information. We can use any XID for this. OFFactory fact = sw.factory(); switch (fact.getVersion()) { case OF_10: sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build()); break; case OF_13: sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build()); break; default: LOG.warn("Unhandled protocol version"); } }
private void applyRule(FlowRule flowRule) { Dpid dpid = Dpid.dpid(flowRule.deviceId().uri()); OpenFlowSwitch sw = controller.getSwitch(dpid); if (sw == null) { return; } FlowRuleExtPayLoad flowRuleExtPayLoad = flowRule.payLoad(); if (hasPayload(flowRuleExtPayLoad)) { OFMessage msg = new ThirdPartyMessage(flowRuleExtPayLoad.payLoad()); sw.sendMsg(msg); return; } sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), Optional.empty(), Optional.of(driverService)).buildFlowAdd()); if (adaptiveFlowSampling) { // Add TypedFlowEntry to deviceFlowEntries in NewAdaptiveFlowStatsCollector NewAdaptiveFlowStatsCollector collector = afsCollectors.get(dpid); if (collector != null) { collector.addWithFlowRule(flowRule); } } }
@Override public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) { final Dpid dpid = dpid(deviceId.uri()); OpenFlowSwitch sw = controller.getSwitch(dpid); if (sw == null || !sw.isConnected()) { LOG.error("Failed to change portState on device {}", deviceId); return; } OFPortMod.Builder pmb = sw.factory().buildPortMod(); OFPort port = OFPort.of((int) portNumber.toLong()); pmb.setPortNo(port); if (enable) { pmb.setConfig(0x0); // port_down bit 0 } else { pmb.setConfig(0x1); // port_down bit 1 } pmb.setMask(0x1); pmb.setAdvertise(0x0); for (OFPortDesc pd : sw.getPorts()) { if (pd.getPortNo().equals(port)) { pmb.setHwAddr(pd.getHwAddr()); break; } } sw.sendMsg(Collections.singletonList(pmb.build())); }
OFFlowStatsReply.Builder fsr = getSwitch(dpid).factory().buildFlowStatsReply(); List<OFFlowStatsEntry> entries = new LinkedList<>(); for (OFCalientFlowStatsEntry entry : ((OFCalientFlowStatsReply) msg).getEntries()) { .instructions() .applyActions(Collections.singletonList(action)); OFFlowStatsEntry fs = getSwitch(dpid).factory().buildFlowStatsEntry() .setMatch(entry.getMatch()) .setTableId(entry.getTableId()) OFPortStatus.Builder portStatus = this.getSwitch(dpid).factory().buildPortStatus(); OFPortDesc.Builder portDesc = this.getSwitch(dpid).factory().buildPortDesc(); portDesc.setPortNo(circuitPortStatus.getPortNo()) .setHwAddr(circuitPortStatus.getHwAddr())
.set(AnnotationKeys.PROTOCOL, sw.factory().getVersion().toString()) .set(AnnotationKeys.CHANNEL_ID, sw.channelId()) .set(AnnotationKeys.MANAGEMENT_ADDRESS, sw.channelId().split(":")[0])