public static PhysAddress getDefaultInstance(String defaultValue) { return new PhysAddress(defaultValue); }
public static PhysAddress getDefaultInstance(String defaultValue) { return new PhysAddress(defaultValue); }
public static PhysAddress getDefaultInstance(String defaultValue) { return new PhysAddress(defaultValue); }
public static PhysAddress getDefaultInstance(String defaultValue) { return new PhysAddress(defaultValue); }
public static List<PhysAddress> getPhysAddress(List<String> macAddress) { List<PhysAddress> physAddresses = new ArrayList<>(); for (String mac : macAddress) { physAddresses.add(new PhysAddress(mac)); } return physAddresses; }
@Nonnull @Override public List<L2FibEntryKey> getAllIds(@Nonnull final InstanceIdentifier<L2FibEntry> id, @Nonnull final ReadContext ctx) throws ReadFailedException { final BridgeDomainKey bridgeDomainKey = id.firstKeyOf(BridgeDomain.class); final int bdId = bdContext.getIndex(bridgeDomainKey.getName(), ctx.getMappingContext()); LOG.debug("Reading L2 FIB for bridge domain {} (bdId={})", bridgeDomainKey, bdId); return dumpL2Fibs(id, bdId).stream() .map(entry -> new L2FibEntryKey(new PhysAddress(vppPhysAddrToYang(entry.mac)))) .collect(Collectors.toList()); }
@Nonnull @Override public List<L2FibEntryKey> getAllIds(@Nonnull final InstanceIdentifier<L2FibEntry> id, @Nonnull final ReadContext ctx) throws ReadFailedException { final BridgeDomainKey bridgeDomainKey = id.firstKeyOf(BridgeDomain.class); final int bdId = bdContext.getIndex(bridgeDomainKey.getName(), ctx.getMappingContext()); LOG.debug("Reading L2 FIB for bridge domain {} (bdId={})", bridgeDomainKey, bdId); try { return dumpL2Fibs(id, bdId).stream() .map(entry -> new L2FibEntryKey( new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(entry.mac), 2)))) .collect(Collectors.toList()); } catch (VppBaseCallException e) { throw new ReadFailedException(id, e); } }
private void checkAndFireMacChangedNotification(String interfaceName, InetAddress inetAddr, byte[] macAddressBytes) throws InterruptedException { IpAddress ip = new IpAddress(inetAddr.getHostAddress().toCharArray()); String macAddress = NWUtil.toStringMacAddress(macAddressBytes); PhysAddress mac = new PhysAddress(macAddress); if (!macAddress.equals(macsDB.get(interfaceName + "-" + inetAddr.getHostAddress()))) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("mac address changed for " + inetAddr); } MacChangedBuilder builder = new MacChangedBuilder(); builder.setInterface(interfaceName); builder.setIpaddress(ip); builder.setMacaddress(mac); notificationPublishService.putNotification(builder.build()); } }
private void handleArpRequestFromExternalInterface(String srcInterface, IpAddress srcIP, PhysAddress srcMac, IpAddress targetIP) { Port port = VpnUtil.getNeutronPortForFloatingIp(dataBroker, targetIP); String targetIpValue = targetIP.getIpv4Address().getValue(); if (port == null) { LOG.trace("No neutron port found for with floating ip {}", targetIpValue); return; } MacAddress targetMac = port.getMacAddress(); if (targetMac == null) { LOG.trace("No mac address found for floating ip {}", targetIpValue); return; } LOG.trace("Target destination matches floating IP {} so respond for ARP", targetIpValue); vpnIfManager.processArpRequest(srcIP, srcMac, targetIP, new PhysAddress(targetMac.getValue()), srcInterface); }
@Override public void readCurrentAttributes(@Nonnull final InstanceIdentifier<AfPacket> id, @Nonnull final AfPacketBuilder builder, @Nonnull final ReadContext ctx) throws ReadFailedException { final InterfaceKey key = id.firstKeyOf(Interface.class); final int index = interfaceContext.getIndex(key.getName(), ctx.getMappingContext()); final SwInterfaceDetails ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); if (!isInterfaceOfType( org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev181008.AfPacket.class, ifcDetails)) { return; } final AfPacketDetailsReplyDump dump = afPacketDumpManager.getDump(id, ctx.getModificationCache()) .or(new AfPacketDetailsReplyDump()); // Relying here that parent InterfaceCustomizer was invoked first to fill in the context with initial ifc mapping final AfPacketDetails afPacketDetails = dump.afPacketDetails.stream() .filter(detail -> detail.swIfIndex == index) .findFirst() .orElseThrow(() -> new IllegalArgumentException(format("AfPacket interface %s not found", key.getName()))); LOG.trace("AfPacket interface: {} attributes returned from VPP: {}", key.getName(), afPacketDetails); builder.setMac(new PhysAddress(vppPhysAddrToYang(ifcDetails.l2Address))); builder.setHostInterfaceName(toString(afPacketDetails.hostIfName)); LOG.debug("AfPacket interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); }
private void fireArpReqRecvdNotification(String interfaceName, InetAddress srcInetAddr, byte[] srcMac, InetAddress dstInetAddr, int tableId, BigInteger metadata) throws InterruptedException { String macAddress = NWUtil.toStringMacAddress(srcMac); ArpRequestReceivedBuilder builder = new ArpRequestReceivedBuilder(); builder.setInterface(interfaceName); builder.setOfTableId((long) tableId); builder.setSrcIpaddress(new IpAddress(srcInetAddr.getHostAddress() .toCharArray())); builder.setDstIpaddress(new IpAddress(dstInetAddr.getHostAddress() .toCharArray())); builder.setSrcMac(new PhysAddress(macAddress)); builder.setMetadata(metadata); notificationPublishService.putNotification(builder.build()); }
@Override public Initialized<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev181008.interfaces._interface.Tap> init( @Nonnull final InstanceIdentifier<Tap> id, @Nonnull final Tap readValue, @Nonnull final ReadContext ctx) { // The MAC address & tag is set from interface details, those details are retrieved from cache final InterfaceKey key = id.firstKeyOf(Interface.class); final SwInterfaceDetails ifcDetails; try { ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); } catch (ReadFailedException e) { throw new IllegalStateException(format("Unable to read interface %s", key.getName()), e); } return Initialized.create(getCfgId(id), new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev181008.interfaces._interface.TapBuilder() .setMac(new PhysAddress(vppPhysAddrToYang(ifcDetails.l2Address))) .setTapName(readValue.getTapName()) .setTag(ifcDetails.tag[0] == 0 ? null : toString(ifcDetails.tag)) // tapBuilder.setDeviceInstance(); .build()); }
private void fireArpRespRecvdNotification(String interfaceName, InetAddress inetAddr, byte[] macAddressBytes, int tableId, BigInteger metadata) throws InterruptedException { IpAddress ip = new IpAddress(inetAddr.getHostAddress().toCharArray()); String macAddress = NWUtil.toStringMacAddress(macAddressBytes); PhysAddress mac = new PhysAddress(macAddress); ArpResponseReceivedBuilder builder = new ArpResponseReceivedBuilder(); builder.setInterface(interfaceName); builder.setIpaddress(ip); builder.setOfTableId((long) tableId); builder.setMacaddress(mac); builder.setMetadata(metadata); notificationPublishService.putNotification(builder.build()); }
private void createElanInterface(Port port, String name) { String elanInstanceName = port.getNetworkId().getValue(); List<PhysAddress> physAddresses = new ArrayList<>(); physAddresses.add(new PhysAddress(port.getMacAddress().getValue())); InstanceIdentifier<ElanInterface> id = InstanceIdentifier.builder(ElanInterfaces.class).child(ElanInterface .class, new ElanInterfaceKey(name)).build(); ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName) .setName(name).setStaticMacEntries(physAddresses).setKey(new ElanInterfaceKey(name)).build(); MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, elanInterface); LOG.debug("Creating new ELan Interface {}", elanInterface); }
/** * Remove Mac Address from ElanInterfaceForwardingEntries and ElanForwardingTables * Remove SMAC and DMAC flows. */ public void deleteMacEntryFromDsAndRemoveFlows(IInterfaceManager interfaceManager, String interfaceName, String macAddress, String elanName, WriteTransaction tx, WriteTransaction deleteFlowTx) { LOG.trace("Deleting mac address {} and interface name {} from ElanInterfaceForwardingEntries " + "and ElanForwardingTables DS", macAddress, interfaceName); PhysAddress physAddress = new PhysAddress(macAddress); MacEntry macEntry = getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress); InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName); if (macEntry != null && interfaceInfo != null) { deleteMacFlows(ElanUtils.getElanInstanceByName(broker, elanName), interfaceInfo, macEntry, deleteFlowTx); } tx.delete(LogicalDatastoreType.OPERATIONAL, ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress)); tx.delete(LogicalDatastoreType.OPERATIONAL, ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress)); }
/** * Add Mac Address to ElanInterfaceForwardingEntries and ElanForwardingTables * Install SMAC and DMAC flows. */ public void addMacEntryToDsAndSetupFlows(IInterfaceManager interfaceManager, String interfaceName, String macAddress, String elanName, WriteTransaction tx, WriteTransaction flowWritetx, int macTimeOut) throws ElanException { LOG.trace("Adding mac address {} and interface name {} to ElanInterfaceForwardingEntries and " + "ElanForwardingTables DS", macAddress, interfaceName); BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis())); PhysAddress physAddress = new PhysAddress(macAddress); MacEntry macEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress) .setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp) .setIsStaticAddress(false).build(); InstanceIdentifier<MacEntry> macEntryId = ElanUtils .getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress); tx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, macEntry); InstanceIdentifier<MacEntry> elanMacEntryId = ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress); tx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry); ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName); setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut, macAddress, flowWritetx); }
@Override public void addStaticMacAddress(String elanInstanceName, String interfaceName, String macAddress) { ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(broker, interfaceName); PhysAddress updateStaticMacAddress = new PhysAddress(macAddress); if (existingElanInterface != null) { List<PhysAddress> existingMacAddress = existingElanInterface.getStaticMacEntries(); if (existingMacAddress.contains(updateStaticMacAddress)) { return; } existingMacAddress.add(updateStaticMacAddress); ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName) .setName(interfaceName).setStaticMacEntries(existingMacAddress) .setDescription(existingElanInterface.getDescription()).setKey(new ElanInterfaceKey(interfaceName)) .build(); MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface); } }
@Override public void deleteStaticMacAddress(String elanInstanceName, String interfaceName, String macAddress) throws MacNotFoundException { ElanInterface existingElanInterface = ElanUtils.getElanInterfaceByElanInterfaceName(broker, interfaceName); PhysAddress physAddress = new PhysAddress(macAddress); if (existingElanInterface == null) { return; } List<PhysAddress> existingMacAddress = existingElanInterface.getStaticMacEntries(); if (existingMacAddress.contains(physAddress)) { existingMacAddress.remove(physAddress); ElanInterface elanInterface = new ElanInterfaceBuilder().setElanInstanceName(elanInstanceName) .setName(interfaceName).setStaticMacEntries(existingMacAddress) .setDescription(existingElanInterface.getDescription()).setKey(new ElanInterfaceKey(interfaceName)) .build(); MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface); } else { throw new MacNotFoundException("deleteStaticMacAddress did not find MAC: " + macAddress); } }
private void sendGarpOnInterface(String interfaceName, final IpAddress floatingIpAddress, final String routerId) { if (floatingIpAddress.getIpv4Address() == null) { LOG.warn("Faild to send GARP for IP. recieved IPv6."); NatServiceCounters.garp_sent_ipv6.inc(); return; } try { Port floatingPort = NatUtil.getNeutronPortForFloatingIp(dataBroker, floatingIpAddress); PhysAddress floatingPortMac = new PhysAddress(floatingPort.getMacAddress().getValue()); List<InterfaceAddress> interfaceAddresses = new ArrayList<>(); interfaceAddresses.add(new InterfaceAddressBuilder() .setInterface(interfaceName) .setIpAddress(floatingIpAddress) .setMacaddress(floatingPortMac).build()); SendArpRequestInput sendArpRequestInput = new SendArpRequestInputBuilder().setIpaddress(floatingIpAddress) .setInterfaceAddress(interfaceAddresses).build(); arpUtilService.sendArpRequest(sendArpRequestInput); NatServiceCounters.garp_sent.inc(); } catch (Exception e) { LOG.error("Failed to send GARP request for floating ip {} from interface {}", floatingIpAddress.getIpv4Address().getValue(), interfaceName, e); NatServiceCounters.garp_sent_failed.inc(); } }
@Override public Initialized<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev181008.interfaces._interface.TapV2> init( @Nonnull final InstanceIdentifier<TapV2> id, @Nonnull final TapV2 readValue, @Nonnull final ReadContext ctx) { // The MAC address & tag is set from interface details, those details are retrieved from cache final InterfaceKey key = id.firstKeyOf(Interface.class); final SwInterfaceDetails ifcDetails; try { ifcDetails = dumpManager.getInterfaceDetail(id, ctx, key.getName()); } catch (ReadFailedException e) { throw new IllegalStateException(format("Unable to read interface %s", key.getName()), e); } return Initialized.create(getCfgId(id), new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev181008.interfaces._interface.TapV2Builder() .setMac(new PhysAddress(vppPhysAddrToYang(ifcDetails.l2Address))) .setHostInterfaceName(readValue.getHostInterfaceName()) .setTag(ifcDetails.tag[0] == 0 ? null : toString(ifcDetails.tag)) .setHostBridge(readValue.getHostBridge()) .setHostIpv4Address(readValue.getHostIpv4Address()) .setHostIpv6Address(readValue.getHostIpv6Address()) .setRxRingSize(readValue.getRxRingSize()) .setTxRingSize(readValue.getTxRingSize()) .setHostMac(readValue.getHostMac()) .setHostNamespace(readValue.getHostNamespace()) .build()); }