private String getNeutronMacAddress(String interfaceName) { Port port = dhcpManager.getNeutronPort(interfaceName); if (port!=null) { logger.trace("Port found in neutron. Interface Name {}, port {}", interfaceName, port); return port.getMacAddress(); } logger.trace("Port not found in neutron. Interface Name {}", interfaceName); return null; }
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); }
/** * Populate interface acl builder. * * @param interfaceAclBuilder the interface acl builder * @param port the port */ protected static void populateInterfaceAclBuilder(InterfaceAclBuilder interfaceAclBuilder, Port port) { // Handle security group enabled List<Uuid> securityGroups = port.getSecurityGroups(); if (securityGroups != null) { interfaceAclBuilder.setSecurityGroups(securityGroups); } List<AllowedAddressPairs> aclAllowedAddressPairs = NeutronvpnUtils.getAllowedAddressPairsForAclService( port.getMacAddress(), port.getFixedIps()); // Update the allowed address pair with the IPv6 LLA that is auto configured on the port. aclAllowedAddressPairs.add(NeutronvpnUtils.updateIPv6LinkLocalAddressForAclService(port.getMacAddress())); List<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.AllowedAddressPairs> portAllowedAddressPairs = port.getAllowedAddressPairs(); if (portAllowedAddressPairs != null) { aclAllowedAddressPairs.addAll(NeutronvpnUtils.getAllowedAddressPairsForAclService(portAllowedAddressPairs)); } interfaceAclBuilder.setAllowedAddressPairs(aclAllowedAddressPairs); }
if (port != null && port.getMacAddress() != null) { actionsInfo.add(new ActionInfo(ActionType.set_field_eth_src, new String[] { port.getMacAddress().getValue() })); } else { LOG.warn("No MAC address found for floating IP {}", externalIp);
.getMacAddress().getValue(), NeutronvpnUtils.getIPPrefixFromPort(dataBroker, port), ipList.toString())); } else { result.add(String.format(" %-36s %-19s %-13s %-20s ", port.getUuid().getValue(), port .getMacAddress().getValue(), "Not Assigned", "Not " + "Assigned"));
LOG.debug("L3 Cache Population : Router interface {} found.",port); networkIdToRouterMacCache.put(port.getNetworkId().getValue() , port.getMacAddress());
LOG.debug("L3 Cache Population : Router interface {} found.",port); networkIdToRouterMacCache.put(port.getNetworkId().getValue() , port.getMacAddress().getValue());
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); }
@Deprecated private static org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder createBasicEndpointInputBuilder( Port port) { return new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder().setL2Context( new L2BridgeDomainId(port.getNetworkId().getValue())) .setMacAddress(new MacAddress(port.getMacAddress().getValue())) .setTenant(new TenantId(port.getTenantId().getValue())) .setTimestamp(System.currentTimeMillis()); }
@Deprecated private org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput createUnregisterEndpointInput( Port port, Neutron neutron) { org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInputBuilder inputBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInputBuilder(); L2 l2Ep = new L2Builder().setL2Context(new L2BridgeDomainId(port.getNetworkId().getValue())) .setMacAddress(new MacAddress(port.getMacAddress().getValue())) .build(); inputBuilder.setL2(ImmutableList.of(l2Ep)); // we've registered EP with only first IP so remove only EP with first IP Optional<FixedIps> potentialFirstIp = PortUtils.resolveFirstFixedIps(port); if (potentialFirstIp.isPresent()) { FixedIps firstIp = potentialFirstIp.get(); L3Address l3Address = resolveL3AddressFromPort(port, firstIp, neutron); L3 l3 = new L3Builder().setIpAddress(l3Address.getIpAddress()) .setL3Context(l3Address.getL3Context()) .build(); inputBuilder.setL3(ImmutableList.of(l3)); } return inputBuilder.build(); }
private org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.UnregisterEndpointInput createUnregisterBaseEndpointInput( Port port, Neutron neutron) { UnregisterEndpointInputBuilder inputBuilder = new UnregisterEndpointInputBuilder(); List<AddressEndpointUnreg> list = new ArrayList<>(); AddressEndpointUnregBuilder addrL2EpUnregBuilder = new AddressEndpointUnregBuilder(); addrL2EpUnregBuilder.setAddress(port.getMacAddress().getValue()) .setAddressType(MacAddressType.class) .setContextId(new ContextId(port.getNetworkId().getValue())) .setContextType(MappingUtils.L2_BRDIGE_DOMAIN); list.add(addrL2EpUnregBuilder.build()); Optional<FixedIps> potentialFirstIp = PortUtils.resolveFirstFixedIps(port); if (potentialFirstIp.isPresent()) { ContextId l3ContextId = resolveL3ContextForPort(port, potentialFirstIp.get(), neutron); AddressEndpointUnregBuilder addrL3EpUnregBuilder = new AddressEndpointUnregBuilder(); addrL3EpUnregBuilder.setAddress(MappingUtils.ipAddressToStringIpPrefix(potentialFirstIp.get().getIpAddress())) .setAddressType(IpPrefixType.class) .setContextId(l3ContextId) .setContextType(L3Context.class); list.add(addrL3EpUnregBuilder.build()); } inputBuilder.setAddressEndpointUnreg(list); return inputBuilder.build(); }
private void unregisterEndpointAndRemoveMapping(UnregisterEndpointInput baseEpUnreg, Port port, ReadWriteTransaction rwTx) { boolean isUnregisteredBaseEndpoint = epRegistrator.unregisterEndpoint(baseEpUnreg); if (isUnregisteredBaseEndpoint) { UniqueId portId = new UniqueId(port.getUuid().getValue()); PortByBaseEndpointKey portByBaseEndpointKey = new PortByBaseEndpointKey(port.getMacAddress().getValue(), MacAddressType.class, new ContextId(port.getNetworkId().getValue()), MappingUtils.L2_BRDIGE_DOMAIN); LOG.trace("Removing Port-BaseEndpoint mapping for port {} (device owner {}) and endpoint {}", port.getUuid().getValue(), port.getDeviceOwner(), portByBaseEndpointKey); removeBaseEndpointMappings(portByBaseEndpointKey, portId, rwTx); } }
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 protected void add(InstanceIdentifier<Port> identifier, Port port) { LOG.info("Add port notification handler is invoked..."); List<FixedIps> ipList = port.getFixedIps(); for (FixedIps fixedip : ipList) { if (fixedip.getIpAddress().getIpv4Address() != null) { continue; } if (port.getDeviceOwner().equalsIgnoreCase(Ipv6Constants.NETWORK_ROUTER_INTERFACE)) { // Add router interface ifMgr.addRouterIntf(port.getUuid(), new Uuid(port.getDeviceId()), fixedip.getSubnetId(), port.getNetworkId(), fixedip.getIpAddress(), port.getMacAddress().getValue(), port.getDeviceOwner()); } else { // Add host interface ifMgr.addHostIntf(port.getUuid(), fixedip.getSubnetId(), port.getNetworkId(), fixedip.getIpAddress(), port.getMacAddress().getValue(), port.getDeviceOwner()); } } }
String ipValue = portIP.getIpAddress().getIpv4Address().getValue(); nvpnManager.updateSubnetNodeWithFixedIps(portIP.getSubnetId(), routerId, routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue()); nvpnNatManager.handleSubnetsForExternalRouter(routerId, dataBroker); PhysAddress mac = new PhysAddress(routerPort.getMacAddress().getValue()); LOG.trace("NeutronPortChangeListener Add Subnet Gateway IP {} MAC {} Interface {} VPN {}", portIP.getIpAddress().getIpv4Address(),routerPort.getMacAddress(), routerPort.getUuid().getValue(), vpnId.getValue()); NeutronvpnUtils.createVpnPortFixedIpToPort(dataBroker, vpnId.getValue(), ipValue, routerPort .getUuid().getValue(), routerPort.getMacAddress().getValue(), true, true, false); } else { LOG.error("No IPv4 address assigned to port {)", routerPort.getUuid().getValue());
String IpPrefix = IpPrefixBuild.append("/32").toString(); Adjacency vmAdj = new AdjacencyBuilder().setKey(new AdjacencyKey(IpPrefix)).setIpAddress(IpPrefix) .setMacAddress(port.getMacAddress().getValue()).build(); adjList.add(vmAdj); .getMacAddress() .getValue(), false, true, false);
@Deprecated private void registerEndpointAndStoreMapping( org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput regEpInput, Port port, ReadWriteTransaction rwTx) { boolean isRegisteredEndpoint = epRegistrator.registerEndpoint(regEpInput); if (!isRegisteredEndpoint) { LOG.error("Failed to register an endpoint: {}", regEpInput); return; } UniqueId portId = new UniqueId(port.getUuid().getValue()); EndpointKey epKey = new EndpointKey(new L2BridgeDomainId(port.getNetworkId().getValue()), new MacAddress( port.getMacAddress().getValue())); LOG.trace("Adding Port-Endpoint mapping for port {} (device owner {}) and endpoint {}", port.getUuid() .getValue(), port.getDeviceOwner(), epKey); EndpointByPort endpointByPort = MappingFactory.createEndpointByPort(epKey, portId); rwTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.endpointByPortIid(portId), endpointByPort, true); PortByEndpoint portByEndpoint = MappingFactory.createPortByEndpoint(portId, epKey); rwTx.put(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.portByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()), portByEndpoint, true); }
@Deprecated private void unregisterEndpointAndRemoveMapping( org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput unregEpInput, Port port, ReadWriteTransaction rwTx) { boolean isUnregisteredEndpoint = epRegistrator.unregisterEndpoint(unregEpInput); if (isUnregisteredEndpoint) { UniqueId portId = new UniqueId(port.getUuid().getValue()); EndpointKey epKey = new EndpointKey(new L2BridgeDomainId(port.getNetworkId().getValue()), new MacAddress( port.getMacAddress().getValue())); LOG.trace("Removing Port-Endpoint mapping for port {} (device owner {}) and endpoint {}", port.getUuid() .getValue(), port.getDeviceOwner(), epKey); DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.endpointByPortIid(portId), rwTx); DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, NeutronGbpIidFactory.portByEndpointIid(epKey.getL2Context(), epKey.getMacAddress()), rwTx); } }
private AddressEndpointRegBuilder createBasicMacAddrEpInputBuilder(Port port, NetworkDomainId networkContainment, @Nullable List<EndpointGroupId> endpointGroupsToAdd) { AddressEndpointRegBuilder addrEpbuilder = new AddressEndpointRegBuilder().setAddressType(MacAddressType.class) .setAddress(port.getMacAddress().getValue()) .setAddressType(MacAddressType.class) .setContextType(MappingUtils.L2_BRDIGE_DOMAIN) .setContextId(new ContextId(port.getNetworkId().getValue())) .setTenant(new TenantId(port.getTenantId().getValue())) .setTimestamp(System.currentTimeMillis()); List<EndpointGroupId> epgs = concatEndpointGroups(port.getSecurityGroups(), endpointGroupsToAdd); addrEpbuilder.setEndpointGroup(epgs); if (networkContainment != null) { addrEpbuilder.setNetworkContainment(new NetworkContainmentBuilder().setContainment( new NetworkDomainContainmentBuilder().setNetworkDomainId(networkContainment) .setNetworkDomainType(MappingUtils.SUBNET) .build()).build()); } return addrEpbuilder; }
portUpdated.getAllowedAddressPairs()); interfaceAclBuilder.setAllowedAddressPairs(NeutronvpnUtils.getAllowedAddressPairsForFixedIps( updatedAddressPairs, portOriginal.getMacAddress(), portOriginal.getFixedIps(), portUpdated.getFixedIps()));