/** * Determine whether this packet is an unicast packet or not. * * @return {@code true} is returned only if this packet is an unicast * packet. */ public boolean isUnicast() { return etherFrame.getDestinationAddress().isUnicast(); }
/** * 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()); }
/** * Search for a MAC address table entry specified by the given MAC address * in the MAC address table. * * @param ctx MD-SAL datastore transaction context. * @param eaddr An {@link EtherAddress} instance that specifies the * MAC address. * @return A {@link MacEntry} instance if found. * {@code null} if not found. * @throws VTNException An error occurred. */ private MacEntry getMacEntry(TxContext ctx, EtherAddress eaddr) throws VTNException { // Multicast address should never be found in the MAC address table. MacEntry ment = null; if (eaddr.isUnicast()) { BridgeIdentifier<Vbridge> vbrId = getIdentifier(); ReadWriteTransaction tx = ctx.getReadWriteTransaction(); InstanceIdentifier<MacTableEntry> path = getMacEntryPath(vbrId, eaddr.getMacAddress()); Optional<MacTableEntry> opt = DataStoreUtils.read(tx, path); if (opt.isPresent()) { ment = new CurrentMacEntry(eaddr, opt.get()); } } return ment; }
/** * 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; }
/** * {@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); } }