private List<Resource> convertToResources(Map<LinkKey, Set<TributarySlot>> slotsMap) { // Same TributarySlots are used for both directions Set<Resource> resources = slotsMap.entrySet().stream() .flatMap(x -> x.getValue() .stream() .flatMap(ts -> Stream.of( Resources.discrete(x.getKey().src().deviceId(), x.getKey().src().port()) .resource().child(ts), Resources.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port()) .resource().child(ts)))) .collect(Collectors.toSet()); return (ImmutableList.copyOf(resources)); }
public String pathToString(List<Link> links) { StringBuilder builder = new StringBuilder(); builder.append("{"); for (Link link : links) { builder.append("(Device:" + link.src().deviceId() + " Port:" + link.src().port().toLong()); builder.append(" Device:" + link.dst().deviceId() + " Port:" + link.dst().port().toLong()); builder.append(")"); } builder.append("}"); return builder.toString(); }
private boolean isEdgePort(ConnectPoint point) { // Logical ports are not counted as edge ports nor are infrastructure // ports. Ports that have only edge links are considered edge ports. return !point.port().isLogical() && deviceService.getPort(point) != null && linkService.getLinks(point).stream() .allMatch(link -> link.type() == Type.EDGE); }
@Override public void write(Kryo kryo, Output output, ConnectPoint object) { kryo.writeClassAndObject(output, object.elementId()); kryo.writeClassAndObject(output, object.port()); }
@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; }
/** * Creates ResourceId for a port. * * @param cp ConnectPoint * @return ResourceId */ static DiscreteResourceId resourceId(ConnectPoint cp) { return Resources.discrete(cp.deviceId(), cp.port()).id(); }
@Override public boolean isValid(Link link, ResourceContext context) { changedBwValue = requestBwValue; if (links.contains(link)) { changedBwValue = requestBwValue.isGreaterThan(sharedBwValue) ? requestBwValue.subtract(sharedBwValue) : Bandwidth.bps(0); } return Stream .of(link.src(), link.dst()) .map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource( changedBwValue.bps())).allMatch(context::isAvailable); }
@Override public boolean isValid(Link link, ResourceContext context) { changedBwValue = requestBwValue; if (links.contains(link)) { changedBwValue = requestBwValue.isGreaterThan(sharedBwValue) ? requestBwValue.subtract(sharedBwValue) : Bandwidth.bps(0); } return Stream .of(link.src(), link.dst()) .map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource( changedBwValue.bps())).allMatch(context::isAvailable); }
private void updateFailoverGroup(PointToPointIntent intent, List<Link> links) { GroupKey groupKey = makeGroupKey(intent.id()); TrafficTreatment.Builder tBuilderIn = DefaultTrafficTreatment.builder(); ConnectPoint src = links.get(0).src(); tBuilderIn.setOutput(src.port()); GroupBucket bucket = DefaultGroupBucket.createFailoverGroupBucket(tBuilderIn.build(), src.port(), null); GroupBuckets addBuckets = new GroupBuckets(Collections.singletonList(bucket)); groupService.addBucketsToGroup(src.deviceId(), groupKey, addBuckets, groupKey, intent.appId()); }
/** * Finds the TributarySlots available on the connect point. * * @param cp connect point * @return set of TributarySlots available on the connect point */ Set<TributarySlot> findTributarySlotsOnCp(ConnectPoint cp) { return resourceService.getAvailableResourceValues( Resources.discrete(cp.deviceId(), cp.port()).id(), TributarySlot.class); } }
/** * Finds the TributarySlots available on the connect point. * * @param cp connect point * @return set of TributarySlots available on the connect point */ Set<TributarySlot> findTributarySlotsOnCp(ConnectPoint cp) { return resourceService.getAvailableResourceValues( Resources.discrete(cp.deviceId(), cp.port()).id(), TributarySlot.class); } }
private OutboundPacket packet(TrafficTreatment.Builder builder, ConnectPoint point, ByteBuffer data) { builder.setOutput(point.port()); return new DefaultOutboundPacket(point.deviceId(), builder.build(), data); }
/** * Returns a formatted string representing the given link. * * @param link infrastructure link * @return formatted link string */ public static String linkString(Link link) { return String.format(FMT, link.src().deviceId(), link.src().port(), link.dst().deviceId(), link.dst().port(), link.type(), link.state(), annotations(link.annotations()), link.isExpected()); }
/** * Looks for available Ids associated to the given connection point. * * @param cp the connection point * @param type the type of Id * @return the set of available Ids */ private Set<Identifier<?>> getAvailableIDs(ConnectPoint cp, EncapsulationType type) { return resourceService.getAvailableResourceValues( Resources.discrete(cp.deviceId(), cp.port()).id(), getEncapsulationClass(type) ); }
@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); } }
private void printPortFlowsLoad(ConnectPoint cp, List<FlowEntryWithLoad> typedFlowLoad) { print(" deviceId/Port=%s/%s, %s flows", cp.elementId(), cp.port(), typedFlowLoad.size()); for (FlowEntryWithLoad fel: typedFlowLoad) { StoredFlowEntry sfe = fel.storedFlowEntry(); print(" flowId=%s, state=%s, liveType=%s, life=%s -> %s", Long.toHexString(sfe.id().value()), sfe.state(), sfe.liveType(), sfe.life(), fel.load().isValid() ? fel.load() : "Load{rate=0, NOT VALID}"); } }
private ConnectPoint staticPort(ConnectPoint connectPoint) { Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); // FIXME: need a better way to match the port if (staticPort != null) { for (Port p : deviceService.getPorts(connectPoint.deviceId())) { if (staticPort.equals(p.number().name())) { return new ConnectPoint(p.element().id(), p.number()); } } } return null; }
private ConnectPoint staticPort(ConnectPoint connectPoint) { Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); // FIXME: need a better way to match the port if (staticPort != null) { for (Port p : deviceService.getPorts(connectPoint.deviceId())) { if (staticPort.equals(p.number().name())) { return new ConnectPoint(p.element().id(), p.number()); } } } return null; }
private void printPortSummaryLoad(ConnectPoint cp, SummaryFlowEntryWithLoad summaryFlowLoad) { print(" deviceId/Port=%s/%s, Total=%s, Immediate=%s, Short=%s, Mid=%s, Long=%s, Unknown=%s", cp.elementId(), cp.port(), summaryFlowLoad.totalLoad().isValid() ? summaryFlowLoad.totalLoad() : "Load{rate=0, NOT VALID}", summaryFlowLoad.immediateLoad().isValid() ? summaryFlowLoad.immediateLoad() : "Load{rate=0, NOT VALID}", summaryFlowLoad.shortLoad().isValid() ? summaryFlowLoad.shortLoad() : "Load{rate=0, NOT VALID}", summaryFlowLoad.midLoad().isValid() ? summaryFlowLoad.midLoad() : "Load{rate=0, NOT VALID}", summaryFlowLoad.longLoad().isValid() ? summaryFlowLoad.longLoad() : "Load{rate=0, NOT VALID}", summaryFlowLoad.unknownLoad().isValid() ? summaryFlowLoad.unknownLoad() : "Load{rate=0, NOT VALID}"); } }