/** * Produces device URI from the given DPID. * * @param dpid device dpid * @return device URI */ public static URI uri(Dpid dpid) { return uri(dpid.value); }
/** * Returns DPID created from the given device URI. * * @param uri device URI * @return dpid */ public static Dpid dpid(URI uri) { checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme"); return new Dpid(fromHex(uri.getSchemeSpecificPart())); }
@Override public void roleChanged(DeviceId deviceId, MastershipRole newRole) { switch (newRole) { case MASTER: controller.setRole(dpid(deviceId.uri()), RoleState.MASTER); break; case STANDBY: controller.setRole(dpid(deviceId.uri()), RoleState.EQUAL); break; case NONE: controller.setRole(dpid(deviceId.uri()), RoleState.SLAVE); break; default: LOG.error("Unknown Mastership state : {}", newRole); } LOG.debug("Accepting mastership role change to {} for device {}", newRole, deviceId); }
@Override public void handlePacket(OpenFlowPacketContext pktCtx) { DeviceId id = DeviceId.deviceId(Dpid.uri(pktCtx.dpid().value())); DefaultInboundPacket inPkt = new DefaultInboundPacket( new ConnectPoint(id, PortNumber.portNumber(pktCtx.inPort())), pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed()), pktCtx.cookie()); DefaultOutboundPacket outPkt = null; if (!pktCtx.isBuffered()) { outPkt = new DefaultOutboundPacket(id, null, ByteBuffer.wrap(pktCtx.unparsed())); } OpenFlowCorePacketContext corePktCtx = new OpenFlowCorePacketContext(System.currentTimeMillis(), inPkt, outPkt, pktCtx.isHandled(), pktCtx); providerService.processPacket(corePktCtx); }
OFDescStatsReply desc, OFVersion ofv) { Dpid dpidObj = new Dpid(dpid); driver = driverService.getDriver(DeviceId.deviceId(Dpid.uri(dpidObj))); } catch (ItemNotFoundException e) { driver = driverService.getDriver(desc.getMfrDesc(), desc.getHwDesc(), desc.getSwDesc()); Dpid did = new Dpid(dpid); DefaultDriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId(uri(did)))); OpenFlowSwitchDriver ofSwitchDriver = driver.createBehaviour(handler, OpenFlowSwitchDriver.class);
@Override public final long getId() { return this.dpid.value(); }
@Override public final String getStringId() { return this.dpid.toString(); }
private void pushTableStatistics(Dpid dpid, OFTableStatsReply replies) { DeviceId did = DeviceId.deviceId(Dpid.uri(dpid)); List<TableStatisticsEntry> tableStatsEntries = replies.getEntries().stream() .map(entry -> buildTableStatistics(did, entry)) .filter(Objects::nonNull) .collect(Collectors.toList()); providerService.pushTableStatistics(did, tableStatsEntries); }
@Override public Dpid dpid() { checkPermission(PACKET_READ); return new Dpid(sw.getId()); }
@Override public boolean isReachable(DeviceId deviceId) { OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri())); return sw != null && sw.isConnected(); }
@Override public void switchAdded(Dpid dpid) { if (providerService == null) { return; } DeviceId deviceId = deviceId(uri(dpid)); OpenFlowControlMessageAggregator ofcma = new OpenFlowControlMessageAggregator(metricsService, providerService, deviceId); ScheduledFuture result = executor.scheduleAtFixedRate(ofcma, AGGR_INIT_DELAY, AGGR_PERIOD, AGGR_TIME_UNIT, true); aggregators.put(dpid, ofcma); executorResults.put(dpid, result); }
private void connectInitialDevices() { for (OpenFlowSwitch sw: controller.getSwitches()) { try { listener.switchAdded(new Dpid(sw.getId())); } catch (Exception e) { log.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage()); log.debug("Error details:", e); } } }
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 switchRemoved(Dpid dpid) { if (providerService == null) { return; } providerService.deviceDisconnected(deviceId(uri(dpid))); stopCollectorIfNeeded(collectors.remove(dpid)); }
private void connectInitialDevices() { for (OpenFlowSwitch sw : controller.getSwitches()) { try { listener.switchAdded(new Dpid(sw.getId())); } catch (Exception e) { LOG.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage()); LOG.debug("Error details:", e); // disconnect to trigger switch-add later sw.disconnectSwitch(); } PortStatsCollector psc = new PortStatsCollector(sw, portStatsPollFrequency); psc.start(); collectors.put(new Dpid(sw.getId()), psc); } }
@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 portChanged(Dpid dpid, OFPortStatus status) { LOG.debug("portChanged({},{})", dpid, status); PortDescription portDescription = buildPortDescription(status); providerService.portStatusChanged(deviceId(uri(dpid)), portDescription); }
private void createCollector(OpenFlowSwitch sw) { checkNotNull(sw, "Null switch"); if (adaptiveFlowSampling) { // NewAdaptiveFlowStatsCollector Constructor NewAdaptiveFlowStatsCollector fsc = new NewAdaptiveFlowStatsCollector(driverService, sw, flowPollFrequency); fsc.start(); stopCollectorIfNeeded(afsCollectors.put(new Dpid(sw.getId()), fsc)); } else { FlowStatsCollector fsc = new FlowStatsCollector(timer, sw, flowPollFrequency); fsc.start(); stopCollectorIfNeeded(simpleCollectors.put(new Dpid(sw.getId()), fsc)); } TableStatisticsCollector tsc = new TableStatisticsCollector(timer, sw, flowPollFrequency); tsc.start(); stopCollectorIfNeeded(tableStatsCollectors.put(new Dpid(sw.getId()), tsc)); }
@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"); } }