/** * provides the element id. */ private ElementId elementId(String id) { try { return DeviceId.deviceId(id); } catch (IllegalArgumentException e) { return HostId.hostId(id); } }
@Override public ObjectNode encode(HostToHostIntent intent, CodecContext context) { checkNotNull(intent, "Host to host intent cannot be null"); final JsonCodec<ConnectivityIntent> connectivityIntentCodec = context.codec(ConnectivityIntent.class); final ObjectNode result = connectivityIntentCodec.encode(intent, context); final String one = intent.one().toString(); final String two = intent.two().toString(); result.put(ONE, one); result.put(TWO, two); return result; }
public void removeDuplicates(HostId hostId, HostDescription desc) { desc.ipAddress().forEach(ip -> { Set<Host> allHosts = store.getHosts(ip); allHosts.forEach(eachHost -> { if (!(eachHost.id().equals(hostId))) { log.info("Duplicate ip {} found on host {} and {}", ip, hostId.toString(), eachHost.id().toString()); store.removeIp(eachHost.id(), ip); } }); }); }
@Override public void modifyHostDetails(PropertyPanel pp, HostId hostId) { pp.title(MY_HOST_TITLE); pp.removeAllProps(); PortPairService portPairService = AbstractShellCommand.get(PortPairService.class); VirtualPortService virtualPortService = AbstractShellCommand.get(VirtualPortService.class); HostService hostService = AbstractShellCommand.get(HostService.class); Iterable<PortPair> portPairs = portPairService.getPortPairs(); for (PortPair portPair : portPairs) { VirtualPort vPort = virtualPortService.getPort(VirtualPortId.portId(portPair.ingress())); MacAddress dstMacAddress = vPort.macAddress(); Host host = hostService.getHost(HostId.hostId(dstMacAddress)); if (hostId.toString().equals(host.id().toString())) { pp.addProp("SF Name", portPair.name()); pp.addProp("SF Ip", vPort.fixedIps().iterator().next().ip()); } } pp.addProp("SF host Address", hostId.toString()); }
Host srcHost = hostService.getHost(HostId.hostId(fiveTuple.macSrc())); HostHighlight hSrc = new HostHighlight(srcHost.id().toString()); hSrc.setBadge(NodeBadge.text("SRC")); String sfcPath = "SRC -> "; VirtualPort vPort = virtualPortService.getPort(VirtualPortId.portId(portPair.egress())); MacAddress dstMacAddress = vPort.macAddress(); Host host = hostService.getHost(HostId.hostId(dstMacAddress)); HostHighlight hhDst = new HostHighlight(host.id().toString()); hhDst.setBadge(NodeBadge.text(portPair.name())); sfcPath = sfcPath + portPair.name() + "(" + vPort.fixedIps().iterator().next().ip() + ") -> "; .portId(portPair.ingress())) .macAddress(); Host hostSrc = hostService.getHost(HostId.hostId(srcMacAddress)); HostHighlight hhSrc = new HostHighlight(hostSrc.id().toString()); hhSrc.setBadge(NodeBadge.text(portPair.name())); highlights.add(hhSrc); Host dstHost = hostService.getHost(HostId.hostId(fiveTuple.macDst())); HostHighlight hDst = new HostHighlight(dstHost.id().toString()); hDst.setBadge(NodeBadge.text("DST")); sfcPath = sfcPath + "DST";
@Override protected void doExecute() { get(HostAdminService.class).removeHost(HostId.hostId(id)); }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); HostService service = AbstractShellCommand.get(HostService.class); Iterator<Host> it = service.getHosts().iterator(); SortedSet<String> strings = delegate.getStrings(); while (it.hasNext()) { strings.add(it.next().id().toString()); } // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
private void updateForMode(String id) { log.debug("host service: {}", hostService); log.debug("device service: {}", deviceService); try { HostId hid = HostId.hostId(id); log.debug("host id {}", hid); elementOfNote = hostService.getHost(hid); log.debug("host element {}", elementOfNote); } catch (RuntimeException e) { try { DeviceId did = DeviceId.deviceId(id); log.debug("device id {}", did); elementOfNote = deviceService.getDevice(did); log.debug("device element {}", elementOfNote); } catch (RuntimeException e2) { log.debug("Unable to process ID [{}]", id); elementOfNote = null; } } switch (currentMode) { case MOUSE: sendMouseData(); break; default: break; } }
@Override public ObjectNode encode(ConnectPoint point, CodecContext context) { checkNotNull(point, "Connect point cannot be null"); ObjectNode root = context.mapper().createObjectNode() .put(PORT, point.port().toString()); if (point.elementId() instanceof DeviceId) { root.put(ELEMENT_DEVICE, point.deviceId().toString()); } else if (point.elementId() instanceof HostId) { root.put(ELEMENT_HOST, point.hostId().toString()); } return root; }
@Override public HostToHostIntent decode(ObjectNode json, CodecContext context) { HostToHostIntent.Builder builder = HostToHostIntent.builder(); IntentCodec.intentAttributes(json, context, builder); ConnectivityIntentCodec.intentAttributes(json, context, builder); String one = nullIsIllegal(json.get(ONE), ONE + IntentCodec.MISSING_MEMBER_MESSAGE).asText(); builder.one(HostId.hostId(one)); String two = nullIsIllegal(json.get(TWO), TWO + IntentCodec.MISSING_MEMBER_MESSAGE).asText(); builder.two(HostId.hostId(two)); return builder.build(); } }
@Override public ObjectNode encode(Host host, CodecContext context) { checkNotNull(host, "Host cannot be null"); final JsonCodec<HostLocation> locationCodec = context.codec(HostLocation.class); final ObjectNode result = context.mapper().createObjectNode() .put("id", host.id().toString()) .put("mac", host.mac().toString()) .put("vlan", host.vlan().toString()) .put("innerVlan", host.innerVlan().toString()) .put("outerTpid", host.tpid().toString()) .put("configured", host.configured()); final ArrayNode jsonIpAddresses = result.putArray("ipAddresses"); for (final IpAddress ipAddress : host.ipAddresses()) { jsonIpAddresses.add(ipAddress.toString()); } result.set("ipAddresses", jsonIpAddresses); final ArrayNode jsonLocations = result.putArray("locations"); for (final HostLocation location : host.locations()) { jsonLocations.add(locationCodec.encode(location, context)); } result.set("locations", jsonLocations); return annotate(result, host, context); }
@Override public ConnectPoint decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } ElementId elementId; if (json.has(ELEMENT_DEVICE)) { elementId = DeviceId.deviceId(json.get(ELEMENT_DEVICE).asText()); } else if (json.has(ELEMENT_HOST)) { elementId = HostId.hostId(json.get(ELEMENT_HOST).asText()); } else { // invalid JSON return null; } PortNumber portNumber = portNumber(json.get(PORT).asText()); return new ConnectPoint(elementId, portNumber); } }
public void onVirtualPortCreated(VtnRscEventFeedback l3Feedback) { VirtualPort vPort = l3Feedback.virtualPort(); BasicHostConfig basicHostConfig = networkConfigService.addConfig(HostId.hostId(vPort.macAddress()), BasicHostConfig.class); Set<IpAddress> ips = new HashSet<>(); for (FixedIp fixedIp : vPort.fixedIps()) { ips.add(fixedIp.ip()); } basicHostConfig.setIps(ips).apply(); }
public void onVirtualPortDeleted(VtnRscEventFeedback l3Feedback) { VirtualPort vPort = l3Feedback.virtualPort(); HostId hostId = HostId.hostId(vPort.macAddress()); BasicHostConfig basicHostConfig = networkConfigService.addConfig(hostId, BasicHostConfig.class); Set<IpAddress> ips = hostService.getHost(hostId).ipAddresses(); for (FixedIp fixedIp : vPort.fixedIps()) { ips.remove(fixedIp.ip()); } basicHostConfig.setIps(ips).apply(); }
@Override protected void doExecute() { NetworkConfigService netcfgService = get(NetworkConfigService.class); HostId hostId = HostId.hostId(uri); if (key == null) { print("[ERROR] Annotation key not specified."); return; } HostAnnotationConfig cfg = netcfgService.getConfig(hostId, HostAnnotationConfig.class); if (cfg == null) { cfg = new HostAnnotationConfig(hostId); } if (removeCfg) { // remove config about entry cfg.annotation(key); } else { // add request config cfg.annotation(key, value); } netcfgService.applyConfig(hostId, HostAnnotationConfig.class, cfg.node()); } }
@Override protected void doExecute() { IntentService service = get(IntentService.class); HostId oneId = HostId.hostId(one); HostId twoId = HostId.hostId(two); TrafficSelector selector = buildTrafficSelector(); TrafficTreatment treatment = buildTrafficTreatment(); List<Constraint> constraints = buildConstraints(); HostToHostIntent intent = HostToHostIntent.builder() .appId(appId()) .key(key()) .one(oneId) .two(twoId) .selector(selector) .treatment(treatment) .constraints(constraints) .priority(priority()) .resourceGroup(resourceGroup()) .build(); service.submit(intent); print("Host to Host intent submitted:\n%s", intent.toString()); }
Host host = hostService.getHost(HostId.hostId(srcMacAddress)); PortNumber port = host.location().port();
MacAddress srcMacAddress = virtualPortService.getPort(VirtualPortId.portId(portPair.ingress())).macAddress(); VirtualPort virtualPort = virtualPortService.getPort(VirtualPortId.portId(portPair.ingress())); Host host = hostService.getHost(HostId.hostId(srcMacAddress)); PortNumber port = host.location().port();
HostId hostId = HostId.hostId(subject.hwAddress(), VlanId.vlanId()); DeviceId deviceId = DeviceId.deviceId(uri(subject.dpid().value())); PortNumber portNumber = PortNumber.portNumber(subject break; case PORT_REMOVED: HostId host = HostId.hostId(subject.hwAddress(), VlanId.vlanId()); providerService.hostVanished(host); break;