/** * Determine whether the given Ethernet header matches the condition * for MAC address configured in this instance. * * @param ctx A {@link FlowMatchContext} instance. * @param eth An {@link EtherHeader} instance. * @return {@code true} only if the given Ethernet header matches all * the conditions for MAC address configured in this instance. */ private boolean matchAddress(FlowMatchContext ctx, EtherHeader eth) { if (sourceAddress != null) { ctx.addMatchField(FlowMatchType.DL_SRC); if (sourceAddress.getAddress() != eth.getSourceAddress().getAddress()) { return false; } } // Check the destination MAC address. if (destinationAddress != null) { ctx.addMatchField(FlowMatchType.DL_DST); if (destinationAddress.getAddress() != eth.getDestinationAddress().getAddress()) { return false; } } return true; }
/** * 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); }
/** * Set a MAC address. * * <p> * This method is only for JAXB. * </p> * * @param eaddr An {@link EtherAddress} instance which represents * a MAC address. */ void setEtherAddress(EtherAddress eaddr) { long mac = (eaddr == null) ? UNDEFINED : eaddr.getAddress(); encodedValue = encode(mac, getVlanId()); }
/** * Return the identifier for the virtual mapping which maps the given host. * * @param eaddr An {@link EtherAddress} instance that specifies the MAC * address of the mapped host. * {@code null} should be treated as if the mapped host is * not specified. * @param vid The VLAN ID of the mapped host. * @return The identifier for the virtual network mapping. */ @Override public VBridgeMapIdentifier<?> getIdentifier(EtherAddress eaddr, int vid) { MacMapIdentifier mapId = getIdentifier(); return (eaddr == null) ? mapId : new MacMapHostIdentifier( mapId, new MacVlan(eaddr.getAddress(), vid)); }
/** * 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()); }
/** * 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()); }
/** * Determine whether the given MAC address should be learned in the * MAC address table or not. * * @param pctx A runtime context for a received packet. * @param eaddr An {@link EtherAddress} to be tested. * @return {@code true} only if the given MAC address should be learned * in the MAC address. */ private boolean isMacAddressValid(PacketContext pctx, EtherAddress eaddr) { // Multicast address should be ignored. boolean valid = eaddr.isUnicast(); if (valid) { valid = (eaddr.getAddress() != 0L); if (!valid) { pctx.getTxContext(). log(LOG, VTNLogLevel.WARN, "{}: Ignore zero MAC address: {}", getIdentifier(), pctx.getFrame()); } } return valid; }
/** * Purge VTN flows relevant to the given obsolete layer 2 host. * * @param ment An obsolete MAC address table entry. */ public void removeFlows(MacEntry ment) { long mac = ment.getEtherAddress().getAddress(); L2Host host = new L2Host(mac, ment.getVlanId(), ment.getPort()); String tname = mapReference.getTenantNameString(); txContext.getSpecific(FlowRemoverQueue.class). enqueue(new EdgeHostFlowRemover(tname, host)); }
/** * Determine whether the given host is currently mapped by the MAC mapping * or not. * * @param ctx MD-SAL datastore transaction context. * @param eaddr The MAC address of the host. * @param sport A {@link SalPort} instance that specifies the switch port * where the host was detected. * @param vid The VLAN ID associated with the specified host. * @return {@code true} if the given host is mapped by the MAC mapping. * {@code false} if not mapped. * @throws VTNException An error occurred. */ public boolean isActive(TxContext ctx, EtherAddress eaddr, SalPort sport, int vid) throws VTNException { MacMapStatusReader reader = ctx.getSpecific(MacMapStatusReader.class); MacMapIdentifier mapId = getIdentifier(); VTNMacMapStatus vmst = reader.get(mapId); MacVlan mv = new MacVlan(eaddr.getAddress(), vid); SalPort mapped = vmst.getPort(mv); boolean active = sport.equalsPort(mapped); if (!active && mapped != null) { ctx.log(LOG, VTNLogLevel.WARN, "{}: Unexpected port is mapped: host={}, port={}, " + "mapped={}", mapId, mv, sport, mapped); } return active; }
MacVlan mv = new MacVlan(eaddr.getAddress(), vid); MacMapIdentifier mapId = getMacMapping(rtx, mv); if (mapId != null && checkMacMapping(ctx, mapId, mv, sport, pident)) {
SalPort sport, int vid) throws VTNException { MacMapIdentifier mapId = getIdentifier(); MacVlan mv = new MacVlan(eaddr.getAddress(), vid); try { boolean activated = new MacMapActivation(mapId, mv, sport).
/** * 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()); }
/** * {@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); } }