private PortNumber createPortNumber(long number, String name) { if (name == null) { return PortNumber.portNumber(number); } return PortNumber.portNumber(number, name); }
private static PortNumber portNumber(String portName) { if (portName.equalsIgnoreCase(PORT_NAME_LOCAL)) { return PortNumber.LOCAL; } return PortNumber.portNumber(portName); }
@Override public Criterion decodeCriterion(ObjectNode json) { PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT), CriterionCodec.PORT + MISSING_MEMBER_MESSAGE).asLong()); return Criteria.matchInPort(port); } }
@Override public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> portStats) { ConcurrentMap<PortNumber, PortStatistics> statsMap = devicePortStats.get(deviceId); if (statsMap == null) { statsMap = Maps.newConcurrentMap(); devicePortStats.put(deviceId, statsMap); } for (PortStatistics stat: portStats) { PortNumber portNumber = PortNumber.portNumber(stat.port()); statsMap.put(portNumber, stat); } return new DeviceEvent(PORT_STATS_UPDATED, devices.get(deviceId), null); }
@Override public Criterion decodeCriterion(ObjectNode json) { PortNumber port = PortNumber.portNumber(nullIsIllegal(json.get(CriterionCodec.PORT), CriterionCodec.PORT + MISSING_MEMBER_MESSAGE).asLong()); return Criteria.matchInPhyPort(port); } }
private void updatePortData(DeviceId deviceId, PortStatistics stats) { ConnectPoint cp = new ConnectPoint(deviceId, portNumber(stats.port())); DataPoint c = current.get(cp); // Create a new data point and make it the current one current.put(cp, new DataPoint(stats)); // If we have a current data point, demote it to previous if (c != null) { previous.put(cp, c); } }
@Override public PortNumber read(Kryo kryo, Input input, Class<PortNumber> type) { if (input.readBoolean()) { return PortNumber.portNumber(input.readLong(), input.readString()); } else { return PortNumber.portNumber(input.readLong()); } } }
@Override public NiciraResubmit decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } // parse in port number long portNumberLong = nullIsIllegal(json.get(RESUBMIT_PORT), RESUBMIT_PORT + MISSING_MEMBER_MESSAGE).asLong(); PortNumber portNumber = PortNumber.portNumber(portNumberLong); return new NiciraResubmit(portNumber); } }
/** * Gets the access device configuration for this device. * * @return access device configuration */ public AccessDeviceData getOlt() { PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText()); VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText())); JsonNode defaultVlanNode = node.path(DEFAULT_VLAN); Optional<VlanId> defaultVlan; if (defaultVlanNode.isMissingNode()) { defaultVlan = Optional.empty(); } else { defaultVlan = Optional.of(VlanId.vlanId(Short.parseShort(defaultVlanNode.asText()))); } return new AccessDeviceData(subject(), uplink, vlan, defaultVlan); } }
@Override public NiciraResubmitTable decode(ObjectNode json, CodecContext context) { if (json == null || !json.isObject()) { return null; } // parse in port number long portNumberLong = nullIsIllegal(json.get(RESUBMIT_PORT), RESUBMIT_PORT + MISSING_MEMBER_MESSAGE).asLong(); PortNumber portNumber = PortNumber.portNumber(portNumberLong); // parse table id short tableId = (short) nullIsIllegal(json.get(RESUBMIT_TABLE), RESUBMIT_TABLE + MISSING_MEMBER_MESSAGE).asInt(); return new NiciraResubmitTable(portNumber, tableId); } }
@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); } }
private ConnectPoint connectPoint(PcepDpid id, long port) { return new ConnectPoint(deviceId(uri(id)), portNumber(port)); }
private static PortNumber logicalToPipelineSpecific( PortNumber logicalPort, Device device) throws PiTranslationException { if (!device.is(PiPipelineInterpreter.class)) { throw new PiTranslationException( "missing interpreter, cannot map logical port " + logicalPort.toString()); } final PiPipelineInterpreter interpreter = device.as(PiPipelineInterpreter.class); Optional<Integer> mappedPort = interpreter.mapLogicalPortNumber(logicalPort); if (!mappedPort.isPresent()) { throw new PiTranslationException( "interpreter cannot map logical port " + logicalPort.toString()); } return PortNumber.portNumber(mappedPort.get()); } }
/** * Build a portDescription from a given Ethernet port description. * * @param port the port to build from. * @return portDescription for the port. */ private PortDescription buildPortDescription(OFPortDesc port) { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && !port.getConfig().contains(OFPortConfig.PORT_DOWN); Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); return new DefaultPortDescription(portNo, enabled, type, portSpeed(port), annotations); }
@Override public void handlePacketIn(Bmv2Device device, int inputPort, ImmutableByteSequence packet) { Ethernet ethPkt = new Ethernet(); ethPkt.deserialize(packet.asArray(), 0, packet.size()); DeviceId deviceId = device.asDeviceId(); ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(inputPort)); ByteBuffer rawData = ByteBuffer.wrap(packet.asArray()); InboundPacket inPkt = new DefaultInboundPacket(receivedFrom, ethPkt, rawData); OutboundPacket outPkt = new DefaultOutboundPacket(deviceId, null, rawData); PacketContext pktCtx = new Bmv2PacketContext(System.currentTimeMillis(), inPkt, outPkt, false); providerService.processPacket(pktCtx); } }
@Override protected void doExecute() { StatisticService service = get(StatisticService.class); DeviceId ingressDeviceId = deviceId(getDeviceId(connectPoint)); PortNumber ingressPortNumber = portNumber(getPortNumber(connectPoint)); ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber); Load load = service.load(cp); print("Load on %s -> %s", cp, load); }
/** * Creates packet_out BDDP for specified output port. * * @param port the port * @return Packet_out message with LLDP data */ private OutboundPacket createOutBoundBddp(Long port) { if (port == null) { return null; } ONOSLLDP lldp = getLinkProbe(port); bddpEth.setSourceMACAddress(context.fingerprint()).setPayload(lldp); return new DefaultOutboundPacket(device.id(), builder().setOutput(portNumber(port)).build(), ByteBuffer.wrap(bddpEth.serialize())); }
private PortDescription buildPortDescription(OFPortStatus status) { OFPortDesc port = status.getDesc(); if (status.getReason() != OFPortReason.DELETE) { return buildPortDescription(port); } else { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); return new DefaultPortDescription(portNo, false, type, portSpeed(port), annotations); } }
/** * Creates packet_out LLDP for specified output port. * * @param port the port * @return Packet_out message with LLDP data */ private OutboundPacket createOutBoundLldp(Long port) { if (port == null) { return null; } ONOSLLDP lldp = getLinkProbe(port); ethPacket.setSourceMACAddress(context.fingerprint()).setPayload(lldp); return new DefaultOutboundPacket(device.id(), builder().setOutput(portNumber(port)).build(), ByteBuffer.wrap(ethPacket.serialize())); }
@Override public void handlePacket(OpenFlowPacketContext pktCtx) { DeviceId id = DeviceId.deviceId(Dpid.uri(pktCtx.dpid().value())); DefaultInboundPacket inPkt = new DefaultInboundPacket( new ConnectPoint(id, PortNumber.portNumber(pktCtx.inPort())), pktCtx.parsed(), ByteBuffer.wrap(pktCtx.unparsed()), pktCtx.cookie()); DefaultOutboundPacket outPkt = null; if (!pktCtx.isBuffered()) { outPkt = new DefaultOutboundPacket(id, null, ByteBuffer.wrap(pktCtx.unparsed())); } OpenFlowCorePacketContext corePktCtx = new OpenFlowCorePacketContext(System.currentTimeMillis(), inPkt, outPkt, pktCtx.isHandled(), pktCtx); providerService.processPacket(corePktCtx); }