/** * Create a new {@link EtherAddress} instance. * * @param mac A {@link MacAddress} instance. * @return An {@link EtherAddress} instance if {@code mac} is not * {@code null}. {@code null} if {@code mac} is {@code null}. * @throws IllegalArgumentException * The given instance contains an invalid value. */ public static EtherAddress create(MacAddress mac) { return (mac == null) ? null : new EtherAddress(mac); }
/** * Create a new {@link EtherAddress} instance. * * @param bytes A byte array which represents an ethernet address. * @return An {@link EtherAddress} instance if {@code bytes} is not * {@code null}. {@code null} if {@code bytes} is {@code null}. * @throws IllegalArgumentException * The length of {@code bytes} is not 6. */ public static EtherAddress create(byte[] bytes) { return (bytes == null) ? null : new EtherAddress(bytes); }
/** * Create a new {@link EtherAddress} instance. * * @param hex A hex string which represents an ethernet address. * @return An {@link EtherAddress} instance if {@code hex} is not * {@code null}. {@code null} if {@code hex} is {@code null}. * @throws IllegalArgumentException * The given string is not a string representation of an ethernet * address. */ public static EtherAddress create(String hex) { return (hex == null) ? null : new EtherAddress(hex); }
/** * Return an {@link EtherAddress} instance that represents the given * {@link MacAddress} instance. * * @param mac A {@link MacAddress} instance. * @return An {@link EtherAddress} instance. * {@code null} is returned if no MAC address is configured. */ private EtherAddress decode(MacAddress mac) { if (mac == null) { return null; } try { return new EtherAddress(mac); } catch (RuntimeException e) { // Ignore invalid MacAddress. return null; } }
/** * Return a MAC adderss as an {@link EtherAddress} instance. * * @return An {@link EtherAddress} instance. * Note that {@code null} is returned if no MAC address is * configured in this instance. */ @XmlElement(name = "address", required = true) public EtherAddress getEtherAddress() { long mac = getAddress(); return (mac == UNDEFINED) ? null : new EtherAddress(mac); }
/** * 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); }
/** * 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; }
/** * Return a MD-SAL MAC address. * * @return A {@link MacAddress} instance. * Note that {@code null} is returned if no MAC address is * configured in this instance. */ public MacAddress getMacAddress() { long mac = getAddress(); if (mac == UNDEFINED) { return null; } EtherAddress eaddr = new EtherAddress(mac); return eaddr.getMacAddress(); }
/** * Create a brief description of the ethernet frame. * * @param ether An ethernet frame. * @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(Ethernet ether, SalPort sport, int vid) { EtherAddress src = new EtherAddress(ether.getSourceMACAddress()); EtherAddress dst = new EtherAddress(ether.getDestinationMACAddress()); return getDescription(src, dst, (int)(ether.getEtherType() & MASK_ETHER_TYPE), sport, vid); }
/** * Fetch all modifiable field values from the given packet. * * <p> * Field values already cached in this instance are preserved. * </p> * * @param ether An {@link Ethernet} instance. * @param tag An {@link IEEE8021Q} instance. */ private void fill(Ethernet ether, IEEE8021Q tag) { if (sourceAddress == null) { sourceAddress = new EtherAddress(ether.getSourceMACAddress()); } if (destinationAddress == null) { destinationAddress = new EtherAddress(ether.getDestinationMACAddress()); } if (vlanPriority == VLANPRI_NONE && tag != null) { vlanPriority = (short)NumberUtils.getUnsigned(tag.getPcp()); } }
/** * {@inheritDoc} */ @Override public EtherAddress getSourceAddress() { Values v = getValues(); EtherAddress addr = v.getSourceAddress(); if (addr == null) { addr = new EtherAddress(packet.getSourceMACAddress()); v.setSourceAddress(addr); } return addr; }
/** * {@inheritDoc} */ @Override public EtherAddress getDestinationAddress() { Values v = getValues(); EtherAddress addr = v.getDestinationAddress(); if (addr == null) { addr = new EtherAddress(packet.getDestinationMACAddress()); v.setDestinationAddress(addr); } return addr; }
/** * Send a packet for probing the host specified by the given MAC address * table entry. * * @param ident The identifier for the target vBridge. * @param outq An {@link PacketOutQueue} instance associated with the * current MD-SAL datastore transaction. * @param ment A {@link MacTableEntry} instance. */ private void probe(BridgeIdentifier<Vbridge> ident, PacketOutQueue outq, MacTableEntry ment) { List<IpAddress> addrs = ment.getIpAddresses(); if (!MiscUtils.isEmpty(addrs)) { SalPort egress = SalPort.create(ment); int vid = ment.getVlanId().intValue(); EtherAddress tha = new EtherAddress(ment.getMacAddress()); for (IpAddress ip: addrs) { probe(ident, outq, egress, vid, tha, ip); } } }
/** * Initialize this instance using the given string. * * @param value A string which represents a pair of MAC address and a * VLAN ID. The given string must consist of a MAC address * and VLAN ID (decimal) joined with "@". * An empty MAC address is treated as MAC address is not * specified. * @throws RpcException * {@code parser} contains invalid value. */ private void initialize(String value) throws RpcException { VlanDescParser parser = new VlanDescParser(value, DESC_VLAN_HOST_DESC); String mac = parser.getIdentifier(); long addr; if (mac == null) { addr = UNDEFINED; } else { try { EtherAddress eaddr = new EtherAddress(mac); checkMacMap(eaddr); addr = eaddr.getAddress(); } catch (RuntimeException e) { throw RpcException.getBadArgumentException( "Invalid MAC address in vlan-host-desc: " + value, e); } } stringCache = MiscUtils.toLowerCase(value); encodedValue = encode(addr, parser.getVlanId()); }