private static boolean isSnmpDevice(DeviceId deviceId) { return deviceId.uri().getScheme().equalsIgnoreCase("snmp"); } }
private Pair<String, Integer> extractIpPort() { String info = subject.uri().getSchemeSpecificPart(); int portSeparator = info.lastIndexOf(':'); if (portSeparator == -1) { return Pair.of(info, DEFAULT_PORT); } String ip = info.substring(0, portSeparator); int port = Integer.parseInt(info.substring(portSeparator + 1)); return Pair.of(ip, port); } }
@Override public NetconfDevice getNetconfDevice(IpAddress ip, int port) { for (DeviceId info : netconfDeviceMap.keySet()) { if (info.uri().getSchemeSpecificPart().equals(ip.toString() + ":" + port)) { return netconfDeviceMap.get(info); } } return null; }
/** * Constructs Dummy Device which only holds DeviceId. * * @param did device Id */ public DummyDevice(DeviceId did) { super(new ProviderId(did.uri().getScheme(), "PortCodec"), did, Type.SWITCH, "dummy", "0", "0", "0", new ChassisId(), DefaultAnnotations.EMPTY); } }
@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); }
/** * {@inheritDoc} * * Note: ProviderId is not part of JSON representation. * Returned object will have random ProviderId set. */ @Override public Device decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } DeviceId id = deviceId(json.get(ID).asText()); // TODO: add providerId to JSON if we need to recover them. ProviderId pid = new ProviderId(id.uri().getScheme(), "DeviceCodec"); Type type = Type.valueOf(json.get(TYPE).asText()); String mfr = json.get(MFR).asText(); String hw = json.get(HW).asText(); String sw = json.get(SW).asText(); String serial = json.get(SERIAL).asText(); ChassisId chassisId = new ChassisId(json.get(CHASSIS_ID).asText()); Annotations annotations = extractAnnotations(json, context); return new DefaultDevice(pid, id, type, mfr, hw, sw, serial, chassisId, annotations); } }
@Override public boolean isReachable(DeviceId deviceId) { OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri())); return sw != null && sw.isConnected(); }
private void pollDevices() { for (Device device: deviceService.getAvailableDevices(SWITCH)) { if (device.id().uri().getScheme().equals(SCHEME) && mastershipService.isLocalMaster(device.id())) { executorService.execute(() -> pollingTask(device.id())); } } }
if (!did.uri().getScheme().equals(pid.scheme())) { log.warn("Attempt to inject unexpected scheme {}", did); return;
@Override protected void execute() { MaoPipelineService maoPipelineManager = get(MaoPipelineService.class); Map<DeviceId, DeviceElement> map = maoPipelineManager.debug(); int countSTANDBY = 0; int countINIT = 0; int countOTHER = 0; for(Map.Entry<DeviceId, DeviceElement> de : map.entrySet()){ if(de.getValue().getState() == DeviceElement.State.STANDBY){ countSTANDBY++; }else if(de.getValue().getState() == DeviceElement.State.INIT_WAIT_PORT){ countINIT++; }else{ countOTHER++; } print("%s\t%-16.16s\t%s",de.getKey().uri().getSchemeSpecificPart(), de.getValue().getState(), de.getValue().getPortMap().toString()); } print("\n\nCount: %d, Standby: %d, InitWaitPort: %d, Other: %d\nPoolSize: %d, ActiveCount: %d, TaskCount: %d, CompleteTask: %d", map.size(), countSTANDBY, countINIT, countOTHER, DeviceElement.getPoolSize(), DeviceElement.getActiveCount(), DeviceElement.getTaskCount(), DeviceElement.getCompletedTaskCount()); } }
did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH), basic.map(BasicDeviceConfig::manufacturer).orElse(unk),
/** * Returns a description of the given device. * * @param device the device * @return a description of the device */ public static DeviceDescription descriptionOf(Device device) { checkNotNull(device, "Must supply non-null Device"); return new DefaultDeviceDescription(device.id().uri(), device.type(), device.manufacturer(), device.hwVersion(), device.swVersion(), device.serialNumber(), device.chassisId(), (SparseAnnotations) device.annotations()); } }
private void deviceAdded(RestSBDevice nodeId) { Preconditions.checkNotNull(nodeId, ISNOTNULL); DeviceId deviceId = nodeId.deviceId(); ChassisId cid = new ChassisId(); String ipAddress = nodeId.ip().toString(); SparseAnnotations annotations = DefaultAnnotations.builder() .set(IPADDRESS, ipAddress) .set(AnnotationKeys.PROTOCOL, REST.toUpperCase()) .build(); DeviceDescription deviceDescription = new DefaultDeviceDescription( deviceId.uri(), Device.Type.SWITCH, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations); nodeId.setActive(true); providerService.deviceConnected(deviceId, deviceDescription); addedDevices.add(deviceId); }
@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); } } }
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); } } }
@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"); } }
@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())); }
new DefaultDeviceDescription(did.uri(), sw.deviceType(), sw.manufacturerDescription(), sw.hardwareDescription(),