/** * Returns device identifier. * * @return device identifier * @throws IllegalArgumentException if the JSON is invalid */ private DeviceId getDeviceId() { JsonNode deviceIdNode = json.get(InstructionCodec.DEVICE_ID); if (deviceIdNode != null) { return DeviceId.deviceId(deviceIdNode.asText()); } throw new IllegalArgumentException("Empty device identifier"); }
@Override public int hashCode() { return Objects.hash(type, deviceId.toString(), load, rate, count, timestamp); }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof PendingFlowObjective)) { return false; } final PendingFlowObjective other = (PendingFlowObjective) obj; return this.deviceId.equals(other.deviceId) && this.flowObj.equals(other.flowObj); } }
@Override protected void doExecute() { if (!isNullOrEmpty(meterstr)) { meterId = MeterId.meterId(Long.parseLong(meterstr)); } MeterService service = get(MeterService.class); if (meterId != null && uri != null) { Meter m = service.getMeter(DeviceId.deviceId(uri), meterId); if (m != null) { print("%s", m); } else { error("Meter %s not found for device %s", meterId, uri); } } else { Collection<Meter> meters = service.getAllMeters(); if (uri == null) { printMeters(meters); } else { printMeters(Collections2.filter(meters, m -> m.deviceId().equals(DeviceId.deviceId(uri)))); } } }
/** * {@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 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 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 DeviceId read(Kryo kryo, Input input, Class<DeviceId> type) { final String str = input.readString(); return DeviceId.deviceId(str); } }
@Override public int hashCode() { return Objects.hash(type, deviceId.toString(), load, rate, count, timestamp); }
@Override public Set<Host> getConnectedHosts(DeviceId deviceId) { Set<Host> hostset = new HashSet<>(); for (ConnectPoint p : locations.keySet()) { if (p.deviceId().equals(deviceId)) { hostset.addAll(locations.get(p)); } } return hostset; }
@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; }
/** * Initialize a label resource object. * @param deviceId device identifier * @param labelResourceId label resource id */ public DefaultLabelResource(String deviceId, long labelResourceId) { this.deviceId = DeviceId.deviceId(deviceId); this.labelResourceId = LabelResourceId.labelResourceId(labelResourceId); }
/** * Instantiates a new Alarm id. * * @param id the device id * @param uniqueIdentifier the unique identifier of the Alarm on that device */ private AlarmId(DeviceId id, String uniqueIdentifier) { super(id.toString() + ":" + uniqueIdentifier); checkNotNull(id, "device id must not be null"); checkNotNull(uniqueIdentifier, "unique identifier must not be null"); checkArgument(!uniqueIdentifier.isEmpty(), "unique identifier must not be empty"); }
@Override public Collection<Alarm> getAlarms(DeviceId deviceId) { //FIXME: this is expensive, need refactoring when core maps provide different indexes. return ImmutableSet.copyOf(alarmsMap.values().stream() .filter(alarm -> alarm.deviceId().equals(deviceId)) .collect(Collectors.toSet())); }
/** * 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); } }
/** * provides the element id. */ private ElementId elementId(String id) { try { return DeviceId.deviceId(id); } catch (IllegalArgumentException e) { return HostId.hostId(id); } }
@Override public String toString() { return toStringHelper(this) .add("type", type) .add("deviceId", deviceId.toString()) .add("load", load) .add("rate", rate) .add("count", count) .add("timestamp", timestamp) .toString(); } }
private void pruneMap(Map<ConnectPoint, DataPoint> map, DeviceId deviceId) { map.keySet().stream().filter(cp -> deviceId.equals(cp.deviceId())) .collect(Collectors.toSet()).forEach(map::remove); }
@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); }