@Override public void write(Dpid dpid, OFMessage msg) { this.getSwitch(dpid).sendMsg(msg); }
@Override public void send() { checkPermission(PACKET_WRITE); if (block() && isBuilt.get()) { sw.sendMsg(pktout); } }
@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); } } }
/** * 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); }
@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 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); } } }
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); } } }
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); }
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 emit(OutboundPacket packet) { DeviceId devId = packet.sendThrough(); String scheme = devId.toString().split(":")[0]; if (!scheme.equals(this.id().scheme())) { throw new IllegalArgumentException( "Don't know how to handle Device with scheme " + scheme); } Dpid dpid = Dpid.dpid(devId.uri()); OpenFlowSwitch sw = controller.getSwitch(dpid); if (sw == null) { log.warn("Device {} isn't available?", devId); return; } //Ethernet eth = new Ethernet(); //eth.deserialize(packet.data().array(), 0, packet.data().array().length); OFPortDesc p = null; for (Instruction inst : packet.treatment().allInstructions()) { if (inst.type().equals(Instruction.Type.OUTPUT)) { p = portDesc(((OutputInstruction) inst).port()); OFPacketOut po = packetOut(sw, packet.data().array(), p.getPortNo()); sw.sendMsg(po); } } }
@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); } } }
sw.sendMsg(request);
return; sw.sendMsg(groupMod); GroupId groudId = new DefaultGroupId(groupMod.getGroup().getGroupNumber()); pendingGroupOperations.put(groudId, groupOperation);
@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())); }