/** * Create a new {@link EtherAddress} instance. * * @param mf A {@link MacAddressFilter} instance. * Note that MAC address mask is always ignored. * @return An {@link EtherAddress} instance if a valid MAC address is * configured in {@code mf}. Otherwise {@code null}. * @throws IllegalArgumentException * The given instance contains an invalid value. */ public static EtherAddress create(MacAddressFilter mf) { return (mf == null) ? null : create(mf.getAddress()); }
/** * Convert the given {@link MacAddress} instance into an * {@link EtherAddress} instance. * * @param mac A {@link MacAddress} instance. * @return An {@link EtherAddress} instance. * {@code null} if {@code mac} is {@code null}. * @throws RpcException * The given MAC address is invalid. */ public static EtherAddress toEtherAddress(MacAddress mac) throws RpcException { try { return EtherAddress.create(mac); } catch (RuntimeException e) { // This should never happen. String msg = "Invalid MAC address: " + mac; throw RpcException.getBadArgumentException(msg, e); } }
/** * {@inheritDoc} */ @Override public EtherAddress getControllerMacAddress() throws Exception { VtnConfig vcfg = getVtnConfig(); MacAddress maddr = vcfg.getControllerMacAddress(); EtherAddress mac = EtherAddress.create(maddr); if (mac == null) { throw new IllegalStateException("Invalid MAC address: " + maddr); } return mac; }
/** * Construct a new instance. * * @param mac A MAC address. * {@code null} is treated as undefined value. * @param vlan VLAN ID. Only lower 12 bits in the value is used. */ public MacVlan(MacAddress mac, int vlan) { EtherAddress eaddr = EtherAddress.create(mac); long addr = (eaddr == null) ? UNDEFINED : eaddr.getAddress(); encodedValue = encode(addr, vlan); }
/** * Return the MAC address configured to the specified network interrace. * * @param nif A {@link NetworkInterface} instance. * @return An {@link EtherAddress} instance on success. * {@code null} if the MAC address is not available. * @throws SocketException An error occurred. */ private static EtherAddress getMacAddress(NetworkInterface nif) throws SocketException { EtherAddress eaddr; if (nif.isLoopback() || nif.isVirtual() || nif.isPointToPoint()) { eaddr = null; } else { eaddr = EtherAddress.create(nif.getHardwareAddress()); } return eaddr; }
/** * Return the MAC address in the given {@link MacAddressFilter} instance. * * @param mf A {@link MacAddressFilter} instance. * @param desc A brief description about the given MAC address. * @return An {@link EtherAddress} instance. * @throws RpcException * The given MAC address is invalid. */ private EtherAddress getMacAddress(MacAddressFilter mf, String desc) throws RpcException { // Exception check can be removed when RESTCONF implements the // restriction check. try { return EtherAddress.create(mf); } catch (RuntimeException e) { String msg = MiscUtils.joinColon(mf, e.getMessage()); throw invalidMacAddress(msg, desc, e); } }
/** * Return the MAC address in the given {@link MacAddress} instance. * * @param mac A {@link MacAddress} instance. * @param desc A brief description about the given MAC address. * @return An {@link EtherAddress} instance. * @throws RpcException * The given MAC address is invalid. */ private EtherAddress getMacAddress(MacAddress mac, String desc) throws RpcException { // Exception check can be removed when RESTCONF implements the // restriction check. try { return EtherAddress.create(mac); } catch (RuntimeException e) { String msg = MiscUtils.joinColon(mac, e.getMessage()); throw invalidMacAddress(msg, desc, e); } }
/** * Verify the given MAC address. * * @param mac The MAC address to be tested. * @return The given MAC address is returned. * @throws RpcException * The given MAC address is invalid. */ public static MacAddress verify(MacAddress mac) throws RpcException { try { EtherAddress eaddr = EtherAddress.create(mac); if (eaddr == null) { throw RpcException.getNullArgumentException("MAC address"); } } catch (RuntimeException e) { throw RpcException.getBadArgumentException( "Invalid MAC address: " + mac, e); } return mac; } }
/** * Construct a new instance. * * @param vh A {@link VlanHost} instance. * @throws RpcException * An invalid value is specified to {@code vh}. */ public MacVlan(VlanHost vh) throws RpcException { if (vh == null) { throw RpcException.getNullArgumentException("vlan-host"); } Integer vid = ProtocolUtils.getVlanId(vh.getVlanId()); if (vid == null) { throw RpcException.getNullArgumentException("VLAN ID"); } EtherAddress eaddr = EtherAddress.create(vh.getMacAddress()); long addr = (eaddr == null) ? UNDEFINED : eaddr.getAddress(); encodedValue = encode(addr, vid.intValue()); }