/** * Return a string representation of this object. * * @return A string representation of this object. */ @Override public String toString() { StringBuilder builder = new StringBuilder("EtherAddress["); return builder.append(getText()).append(']').toString(); } }
/** * {@inheritDoc} */ @Override protected final void appendContents(StringBuilder builder) { builder.append("addr=").append(address.getText()); super.appendContents(builder); }
/** * Create a brief description of the ethernet frame. * * @param src The source MAC address. * @param dst The destination MAC address. * @param type The ethernet type. * @param sport A {@link SalPort} instance associated with the ethernet * frame. * @param vid VLAN ID. * @return A brief description of the specified ethernet frame. */ public String getDescription(EtherAddress src, EtherAddress dst, int type, SalPort sport, int vid) { StringBuilder builder = new StringBuilder("src="); builder.append(src.getText()). append(", dst=").append(dst.getText()); if (sport != null) { builder.append(", port=").append(sport); } builder.append(", type=0x").append(Integer.toHexString(type)). append(", vlan=").append(vid); return builder.toString(); }
/** * {@inheritDoc} */ @Override public void setDescription(StringBuilder builder) { EtherAddress src = getSourceAddress(); EtherAddress dst = getDestinationAddress(); builder.append("Ether[src=").append(src.getText()). append(",dst=").append(dst.getText()). append(",type=0x").append(Integer.toHexString(etherType)); int vid = getVlanId(); if (vid != VLAN_NONE) { builder.append(",vlan={id=").append(vid). append(",pcp=").append((int)getVlanPriority()).append('}'); } builder.append(']'); } }
/** * Return a string representation of this instance. * * @return A string representation of this instance. */ @Override public final String toString() { StringBuilder builder = new StringBuilder("mac-table-entry[mac="). append(etherAddress.getText()). append(", port=").append(port). append(", vid=").append(vlanId). append(", mapPath=").append(getMapPath()); Set<IpNetwork> ipSet = getIpNetworkSet(); if (!ipSet.isEmpty()) { builder.append(", ipaddr=").append(ipSet); } return builder.append(']').toString(); } }
/** * Return a string representation of this object. * * @return A string representation of this object. */ @Override public String toString() { String value = stringCache; if (value == null) { StringBuilder builder = new StringBuilder(); long mac = getAddress(); if (mac != UNDEFINED) { EtherAddress eaddr = new EtherAddress(mac); builder.append(eaddr.getText()); } value = builder.append(VlanDescParser.SEPARATOR). append(getVlanId()).toString(); stringCache = value; } return value; }
/** * Create an exception that indicates the same MAC address is configured * in the allowed host set. * * @param mac A MAC address. * @return A {@link RpcException} instance. */ public static RpcException getDuplicateMacAddressException(long mac) { String maddr = new EtherAddress(mac).getText(); return RpcException.getBadArgumentException( "Duplicate MAC address in allowed set: " + maddr); }
/** * Create an exception that indicates the specified MAC address is already * mapped to this vBridge. * * @param mac A MAC address. * @return A {@link RpcException} instance. */ public static RpcException getAlreadyMappedException(long mac) { String maddr = new EtherAddress(mac).getText(); return RpcException.getDataExistsException( "Already mapped to this vBridge: " + maddr); }
/** * Construct a new instance. * * @param provider A VTN Manager provider service. */ public VTNConfigManager(VTNManagerProvider provider) { XmlConfigFile.init(); // Determine MAC address of the local node. EtherAddress ea = getLocalMacAddress(); VTNConfigImpl vconf = new VTNConfigImpl(ea); if (ea == null) { ea = vconf.getControllerMacAddress(); LOG.warn("Use custom MAC address as local address: {}", ea.getText()); } else { LOG.info("Local MAC address: {}", ea.getText()); } current = new AtomicReference<VTNConfigImpl>(vconf); try { initialize(provider, ea); } catch (RuntimeException e) { LOG.error("Failed to initialize VTN config manager.", e); close(); throw e; } }
/** * Send a packet for probing the specified host. * * @param ident The identifier for the target vBridge. * @param outq An {@link PacketOutQueue} instance associated with the * current MD-SAL datastore transaction. * @param egress A {@link SalPort} instance that specifies the egress * switch port. * @param vid A VLAN ID to be set in an ARP request. * @param tha The target hardware address. * @param tpa The target protocol address. */ private void probe(BridgeIdentifier<Vbridge> ident, PacketOutQueue outq, SalPort egress, int vid, EtherAddress tha, IpAddress tpa) { if (tpa != null) { Ip4Network ip4 = Ip4Network.create(tpa.getIpv4Address()); if (ip4 != null) { // Send an ARP request. if (LOG.isTraceEnabled()) { LOG.trace("{}: Sending an ARP request: mac={}, ip={}, " + "vid={}, port={}", ident, tha.getText(), ip4.getText(), vid, egress); } Ethernet ether = new ArpPacketBuilder(vid). build(senderAddress, tha, ip4); outq.enqueue(egress, ether); } } }
/** * Ensure that the given MAC address is suitable for MAC mapping. * * @param eaddr An {@link EtherAddress} instance. * @throws RpcException * An invalid address is specified to {@code mac}. */ private void checkMacMap(EtherAddress eaddr) throws RpcException { String badaddr = null; if (eaddr.isBroadcast()) { badaddr = "Broadcast address"; } else if (!eaddr.isUnicast()) { badaddr = "Multicast address"; } else if (eaddr.getAddress() == UNDEFINED) { badaddr = "Zero MAC address"; } else { return; } throw RpcException.getBadArgumentException( badaddr + " cannot be specified: " + eaddr.getText()); }
/** * Try to probe IP address of the source address of this packet. */ public void probeInetAddress() { Inet4Packet ipv4 = getInet4Packet(); if (ipv4 != null) { // Send an ARP request to the source address of this packet. EtherAddress src = getControllerAddress(); Ip4Network tpa = ipv4.getSourceAddress(); EtherAddress dst = etherFrame.getSourceAddress(); int vlan = etherFrame.getOriginalVlan(); Ethernet ether = new ArpPacketBuilder(vlan).build(src, dst, tpa); SalPort sport = ingressPort; if (LOG.isTraceEnabled()) { String dstmac = dst.getText(); String target = tpa.getText(); LOG.trace("Sending an ARP request to detect IP address: " + "dst={}, tpa={}, vlan={}, port={}", dstmac, target, vlan, sport); } transmit(sport, ether); } }
/** * {@inheritDoc} */ @Override protected final void verifyImpl() throws RpcException { if (address == null) { String msg = getErrorMessage("MAC address"); throw RpcException.getNullArgumentException(msg); } if (address.isBroadcast()) { String msg = getErrorMessage( "Broadcast address cannot be specified."); throw RpcException.getBadArgumentException(msg); } if (!address.isUnicast()) { String msg = getErrorMessage( "Multicast address cannot be specified", address.getText()); throw RpcException.getBadArgumentException(msg); } if (address.getAddress() == 0L) { String msg = getErrorMessage("Zero cannot be specified."); throw RpcException.getBadArgumentException(msg); } }