/** * Returns the routing control plane connect point. * * @return control plane connect point */ public ConnectPoint getControlPlaneConnectPoint() { return ConnectPoint.deviceConnectPoint(object.path(CP_CONNECT_POINT).asText()); }
private BgpConfig.BgpSpeakerConfig getSpeaker() { ConnectPoint connectPoint = ConnectPoint. deviceConnectPoint(connectionPoint); return new BgpConfig.BgpSpeakerConfig(Optional.ofNullable(name), vlanIdObj, connectPoint, new HashSet<IpAddress>()); } }
private boolean areOltsValid() { JsonNode olts = node.get(OLTS); if (!olts.isObject()) { return false; } return Iterators.all(olts.fields(), item -> ConnectPoint.deviceConnectPoint(item.getKey()) != null && isMacAddress((ObjectNode) olts, item.getKey(), MANDATORY)); } }
/** * Gets the router configurations. * * @return set of router configurations */ public Set<Router> getRouters() { Set<Router> routers = new HashSet<>(); for (JsonNode routerNode : array) { ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(routerNode.path(CP_CONNECT_POINT).asText()); boolean ospfEnabled = routerNode.path(OSPF_ENABLED).asBoolean(); JsonNode intfNode = routerNode.path(INTERFACES); if (intfNode.isMissingNode() || !intfNode.isArray()) { continue; } ArrayNode array = (ArrayNode) intfNode; Set<String> interfaces = new HashSet<>(array.size()); for (JsonNode intf : array) { interfaces.add(intf.asText()); } routers.add(new Router(connectPoint, ospfEnabled, interfaces)); } return routers; }
/** * Gets the access agent configuration for this device. * * @return access agent configuration */ public AccessAgentData getAgent() { JsonNode olts = node.get(OLTS); Map<ConnectPoint, MacAddress> oltMacInfo = Maps.newHashMap(); olts.fields().forEachRemaining(item -> oltMacInfo.put( ConnectPoint.deviceConnectPoint(item.getKey()), MacAddress.valueOf(item.getValue().asText()))); MacAddress agentMac = MacAddress.valueOf(node.path(AGENT_MAC).asText()); JsonNode vtn = node.path(VTN_LOCATION); Optional<ConnectPoint> vtnLocation; if (vtn.isMissingNode()) { vtnLocation = Optional.empty(); } else { vtnLocation = Optional.of(ConnectPoint.deviceConnectPoint(vtn.asText())); } return new AccessAgentData(subject(), oltMacInfo, agentMac, vtnLocation); }
/** * Gets the set of configured BGP speakers. * * @return BGP speakers */ public Set<BgpSpeakerConfig> bgpSpeakers() { Set<BgpSpeakerConfig> speakers = Sets.newHashSet(); JsonNode speakersNode = object.get(SPEAKERS); if (speakersNode == null) { return speakers; } speakersNode.forEach(jsonNode -> { Set<IpAddress> listenAddresses = Sets.newHashSet(); jsonNode.path(PEERS).forEach(addressNode -> listenAddresses.add(IpAddress.valueOf(addressNode.asText())) ); Optional<String> name; if (jsonNode.get(NAME) == null) { name = Optional.empty(); } else { name = Optional.of(jsonNode.get(NAME).asText()); } VlanId vlan = getVlan(jsonNode); speakers.add(new BgpSpeakerConfig(name, vlan, ConnectPoint.deviceConnectPoint(jsonNode.path(CONNECT_POINT).asText()), listenAddresses)); }); return speakers; }
@Override protected List<String> choices() { DeviceService deviceService = getService(DeviceService.class); LinkService linkService = getService(LinkService.class); Optional<ConnectPoint> port = Arrays.asList(commandLine.getArguments()).stream() .filter(s -> s.contains(":") && s.contains("/")) .map(s -> { try { return deviceConnectPoint(s); } catch (IllegalArgumentException e) { // silently ill-formed String return null; } }) .filter(Objects::nonNull) .filter(cp -> deviceService.getPort(cp) != null) .findFirst(); if (!port.isPresent()) { // no candidate return Collections.emptyList(); } final ConnectPoint cp = port.get(); return linkService.getLinks(cp).stream() .flatMap(l -> Stream.of(l.src(), l.dst())) .filter(peer -> !cp.equals(peer)) .distinct() .map(ConnectPoint::toString) .collect(Collectors.toList()); }
@Override protected void doExecute() { InterfaceAdminService interfaceService = get(InterfaceAdminService.class); List<InterfaceIpAddress> ipAddresses = Lists.newArrayList(); if (ips != null) { for (String strIp : ips) { ipAddresses.add(InterfaceIpAddress.valueOf(strIp)); } } MacAddress macAddr = mac == null ? null : MacAddress.valueOf(mac); VlanId vlanId = vlan == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(vlan)); Interface intf = new Interface(name, ConnectPoint.deviceConnectPoint(connectPoint), ipAddresses, macAddr, vlanId); interfaceService.add(intf); print("Interface added"); }
@Override protected void doExecute() { InterfaceAdminService interfaceService = get(InterfaceAdminService.class); boolean success = interfaceService.remove( ConnectPoint.deviceConnectPoint(connectPoint), name); if (success) { print("Interface removed"); } else { print("Unable to remove interface"); } }
@Override protected void doExecute() { MulticastRouteService mcastRouteManager = get(MulticastRouteService.class); McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr), IpAddress.valueOf(gAddr), McastRoute.Type.STATIC); mcastRouteManager.add(mRoute); if (ingressPort != null) { ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressPort); mcastRouteManager.addSource(mRoute, ingress); } if (ports != null) { for (String egCP : ports) { ConnectPoint egress = ConnectPoint.deviceConnectPoint(egCP); mcastRouteManager.addSink(mRoute, egress); } } printMcastRoute(mRoute); }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); // Fetch our service and feed it's offerings to the string completer LinkService service = AbstractShellCommand.get(LinkService.class); // Link source the previous argument. String srcArg = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1]; // Generate the device ID/port number identifiers SortedSet<String> strings = delegate.getStrings(); try { ConnectPoint src = ConnectPoint.deviceConnectPoint(srcArg); service.getEgressLinks(src) .forEach(link -> strings.add(link.dst().elementId().toString() + "/" + link.dst().port())); } catch (NumberFormatException e) { System.err.println("Invalid connect-point"); } // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
@Override protected void doExecute() { DeviceService service = get(DeviceService.class); for (String portStr : ports) { ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(portStr); Port port = service.getPort(connectPoint.deviceId(), connectPoint.port()); printPort(port); printVlans(port); } }
@Override protected void doExecute() { LinkService service = get(LinkService.class); ConnectPoint src = deviceConnectPoint(srcCp); ConnectPoint dst = deviceConnectPoint(dstCp); LinkProviderRegistry registry = get(LinkProviderRegistry.class); CliLinkProvider provider = new CliLinkProvider(); LinkProviderService providerService = registry.register(provider); try { providerService.linkDetected(description(service.getLink(src, dst), key, value)); if (both) { providerService.linkDetected(description(service.getLink(dst, src), key, value)); } } finally { registry.unregister(provider); } }
NetworkConfigService netCfgService = get(NetworkConfigService.class); ConnectPoint srcCp = ConnectPoint.deviceConnectPoint(src); if (deviceService.getPort(srcCp) == null) { print("[ERROR] %s does not exist", srcCp); ConnectPoint dstCp = ConnectPoint.deviceConnectPoint(dst); if (deviceService.getPort(dstCp) == null) { print("[ERROR] %s does not exist", dstCp);
@Override protected void doExecute() { MulticastRouteService mcastRouteManager = get(MulticastRouteService.class); if ("*".equals(sAddr) && "*".equals(gAddr)) { // Clear all routes mcastRouteManager.getRoutes().forEach(mcastRouteManager::remove); return; } McastRoute mRoute = new McastRoute(IpAddress.valueOf(sAddr), IpAddress.valueOf(gAddr), McastRoute.Type.STATIC); if (egressList == null) { mcastRouteManager.remove(mRoute); print(D_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source()); } else { // check list for validity before we begin to delete. for (String egress : egressList) { ConnectPoint eCp = ConnectPoint.deviceConnectPoint(egress); mcastRouteManager.removeSink(mRoute, eCp); } print(U_FORMAT_MAPPING, mRoute.type(), mRoute.group(), mRoute.source()); } } }
IntentService service = get(IntentService.class); ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString); ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
FilteredConnectPoint egress = new FilteredConnectPoint(ConnectPoint.deviceConnectPoint(egressDeviceString)); ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString); ingressPoints.add(new FilteredConnectPoint(ingress));
ConnectPoint ingressPoint = ConnectPoint.deviceConnectPoint(ingressDeviceString); ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); egressPoints.add(egress);
@Override protected void doExecute() { DeviceService deviceService = get(DeviceService.class); NetworkConfigService netcfgService = get(NetworkConfigService.class); ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(port); if (deviceService.getPort(connectPoint) == null) { print("Port %s does not exist.", port); return; } if (removeCfg && key == null) { // remove whole port annotation config netcfgService.removeConfig(connectPoint, PortAnnotationConfig.class); print("Annotation Config about %s removed", connectPoint); return; } if (key == null) { print("[ERROR] Annotation key not specified."); return; } PortAnnotationConfig cfg = netcfgService.addConfig(connectPoint, PortAnnotationConfig.class); if (removeCfg) { // remove config about entry cfg.annotation(key); } else { // add remove request config cfg.annotation(key, value); } cfg.apply(); }