public static Optional<FixedIps> resolveFirstFixedIps(Port port) { List<FixedIps> fixedIps = port.getFixedIps(); if (fixedIps != null && !fixedIps.isEmpty()) { return Optional.of(fixedIps.get(0)); } return Optional.absent(); }
@Override public void update(Port port) { // TODO Port IP and port's host ip is stored by Lisp Neutron Service. If // there is change to these fields, the update needs to be processed. LOG.info("Neutron Port updated: Port name: " + port.getName() + " Port Fixed IP: " + (port.getFixedIps() != null ? port.getFixedIps().get(0) : "No Fixed IP assigned")); LOG.debug("Neutron Port Updated : " + port.toString()); }
public Subnet getNeutronSubnet(Port nPort) { if (nPort != null) { try { return neutronVpnService.getNeutronSubnet(nPort.getFixedIps().get(0).getSubnetId()); } catch (Exception e) { logger.warn("Failed to get Neutron Subnet from Port: {}", e); } } return null; }
public static Uuid getSubnetIdForFloatingIp(Port port, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress targetIP) { if (port == null) { return null; } for (FixedIps ip : port.getFixedIps()) { if (Objects.equals(ip.getIpAddress(), targetIP)) { return ip.getSubnetId(); } } return null; }
public static Set<Port> findPortsBySubnet(Uuid subnetUuid, @Nullable Ports ports) { if (ports == null || ports.getPort() == null) { return Collections.emptySet(); } Set<Port> portsWithSubnet = new HashSet<>(); for (Port port : ports.getPort()) { List<FixedIps> fixedIps = port.getFixedIps(); if (fixedIps != null && !fixedIps.isEmpty()) { for (FixedIps ipWithSubnet : fixedIps) { if (ipWithSubnet.getSubnetId().equals(subnetUuid)) { portsWithSubnet.add(port); } } } } return portsWithSubnet; }
@Override protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) { LOG.debug("update port notification handler is invoked..."); if (update.getDeviceOwner().equalsIgnoreCase(Ipv6Constants.NETWORK_ROUTER_INTERFACE)) { ifMgr.updateRouterIntf(update.getUuid(), new Uuid(update.getDeviceId()), update.getFixedIps()); } else { ifMgr.updateHostIntf(update.getUuid(), update.getFixedIps()); } }
public static Port getNeutronPortForFloatingIp(DataBroker broker, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress targetIP) { InstanceIdentifier<Ports> portsIdentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class); Optional<Ports> portsOptional = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, portsIdentifier); if (!portsOptional.isPresent() || portsOptional.get().getPort() == null) { LOG.trace("No neutron ports found"); return null; } for (Port port : portsOptional.get().getPort()) { if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(port.getDeviceOwner()) && port.getFixedIps() != null) { for (FixedIps ip : port.getFixedIps()) { if (Objects.equals(ip.getIpAddress(), targetIP)) { return port; } } } } return null; }
+ port.getName() + " Port Fixed IP: " + (port.getFixedIps() != null ? port.getFixedIps().get(0) : "No Fixed IP assigned")); LOG.debug("Neutron Port Deleted : " + port.toString()); List<FixedIps> fixedIPs = port.getFixedIps(); if (fixedIPs != null && fixedIPs.size() > 0) { Eid eidAddress;
public static Port getNeutronPortForIp(DataBroker broker, IpAddress targetIP, String deviceType) { InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports> portsIdentifier = InstanceIdentifier .create(Neutron.class) .child(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports.class); Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports> portsOptional = read( broker, LogicalDatastoreType.CONFIGURATION, portsIdentifier); if (!portsOptional.isPresent() || portsOptional.get().getPort() == null) { LOG.trace("No neutron ports found"); return null; } for (Port port : portsOptional.get().getPort()) { if (deviceType.equals(port.getDeviceOwner()) && port.getFixedIps() != null) { for (FixedIps ip : port.getFixedIps()) { if (Objects.equals(ip.getIpAddress(), targetIP)) { return port; } } } } return null; }
private String getSubnetIPFromPort(Port port) throws Exception { FixedIps ip = port.getFixedIps().get(0); if (ip == null) { LOG.error("No fixed ip for port " + port.getName()); throw new Exception("No fixed ip for port" + port.getName()); } Uuid subnetId = ip.getSubnetId(); Subnetmap subnetmap = nvManager.updateSubnetmapNodeWithPorts(subnetId, port.getUuid(), null); String subnetIp = subnetmap.getSubnetIp(); return subnetIp; }
@Override protected void remove(InstanceIdentifier<Port> identifier, Port input) { if (LOG.isTraceEnabled()) { LOG.trace("Removing Port : key: " + identifier + ", value=" + input); } Network network = NeutronvpnUtils.getNeutronNetwork(dataBroker, input.getNetworkId()); if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) { //FIXME: This should be removed when support for VLAN and GRE network types is added LOG.error("neutron vpn doesn't support vlan/gre network provider type for the port {} which is part of " + "network {}.", input.getName(), network); return; } NeutronvpnUtils.removeFromPortCache(input); if ((input.getDeviceOwner() != null) && (input.getDeviceId() != null)) { if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) { handleRouterInterfaceRemoved(input); /* nothing else to do here */ return; } } if (input.getFixedIps() != null && !input.getFixedIps().isEmpty()) { handleNeutronPortDeleted(input); } }
private void sendArpRequestsToExtGatewayTask(Router router) { LOG.trace("Send ARP requests to external GW for router {}", router); Port extPort = getRouterExtGatewayPort(router); if (extPort == null) { LOG.trace("External GW port for router {} is missing", router); return; } Collection<String> extInterfaces = getExternalInterfaces(router); if (extInterfaces == null || extInterfaces.isEmpty()) { LOG.trace("No external interfaces defined for router {}", router.getUuid().getValue()); return; } List<FixedIps> fixedIps = extPort.getFixedIps(); if (fixedIps == null || fixedIps.isEmpty()) { LOG.trace("External GW port {} for router {} has no fixed IPs", extPort.getUuid().getValue(), router.getUuid().getValue()); return; } for (FixedIps fixIp : fixedIps) { Uuid subnetId = fixIp.getSubnetId(); IpAddress srcIpAddress = fixIp.getIpAddress(); IpAddress dstIpAddress = getExternalGwIpAddress(subnetId); sendArpRequest(srcIpAddress, dstIpAddress, extInterfaces); } }
private static ContextId resolveL3ContextForPort(Port port, FixedIps portFixedIPs, Neutron neutron) { Set<Port> routerIfacePorts = PortUtils.findRouterInterfacePorts(neutron.getPorts()); for (Port routerIfacePort : routerIfacePorts) { Uuid routerIfacePortSubnet = routerIfacePort.getFixedIps().get(0).getSubnetId(); // if port is in the same subnet as router interface then we want to use L3Context of // router if (portFixedIPs.getSubnetId().equals(routerIfacePortSubnet)) { LOG.trace("Router interface port was found in the same subnet as port have {}", port); return new ContextId(routerIfacePort.getDeviceId()); } } return new ContextId(port.getNetworkId().getValue()); } }
/** * 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); }
public static NeutronRouter_Interface convertMDSalInterfaceToNeutronRouterInterface( Port routerInterface) { NeutronRouter_Interface neutronInterface = new NeutronRouter_Interface(); String id = String.valueOf(routerInterface.getUuid().getValue()); neutronInterface.setID(id); if (routerInterface.getTenantId() != null) { neutronInterface.setTenantID(routerInterface.getTenantId().getValue()); } neutronInterface.setSubnetUUID(routerInterface.getFixedIps().get(0).getSubnetId().getValue()); neutronInterface.setPortUUID(routerInterface.getUuid().getValue()); return neutronInterface; }
public static NeutronRouter_Interface convertMDSalInterfaceToNeutronRouterInterface( Port routerInterface) { NeutronRouter_Interface neutronInterface = new NeutronRouter_Interface(); String id = String.valueOf(routerInterface.getUuid().getValue()); neutronInterface.setID(id); if (routerInterface.getTenantId() != null) { neutronInterface.setTenantID(routerInterface.getTenantId().getValue()); } neutronInterface.setSubnetUUID(routerInterface.getFixedIps().get(0).getSubnetId().getValue()); neutronInterface.setPortUUID(routerInterface.getUuid().getValue()); return neutronInterface; }
protected void deleteVpnInterface(Uuid vpnId, Port port) { if (port != null) { boolean isLockAcquired = false; String infName = port.getUuid().getValue(); InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName); try { isLockAcquired = NeutronvpnUtils.lock(lockManager, infName); LOG.debug("Deleting vpn interface {}", infName); MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier); List<FixedIps> ips = port.getFixedIps(); for (FixedIps ip : ips) { String ipValue = ip.getIpAddress().getIpv4Address().getValue(); NeutronvpnUtils.removeVpnPortFixedIpToPort(dataBroker, vpnId.getValue(), ipValue); } } catch (Exception ex) { LOG.error("Deletion of vpninterface {} failed due to {}", infName, ex); } finally { if (isLockAcquired) { NeutronvpnUtils.unlock(lockManager, infName); } } } }
@Deprecated private static L3Address resolveL3AddressFromPort(Port port, FixedIps portFixedIPs, Neutron neutron) { Set<Port> routerIfacePorts = PortUtils.findRouterInterfacePorts(neutron.getPorts()); for (Port routerIfacePort : routerIfacePorts) { Uuid routerIfacePortSubnet = routerIfacePort.getFixedIps().get(0).getSubnetId(); // if port is in the same subnet as router interface then we want to use L3Context of // router if (portFixedIPs.getSubnetId().equals(routerIfacePortSubnet)) { L3ContextId epL3ContextId = new L3ContextId(routerIfacePort.getDeviceId()); LOG.trace("Router interface port was found in the same subnet as port have {}", port); return new L3AddressBuilder().setL3Context(epL3ContextId) .setIpAddress(portFixedIPs.getIpAddress()) .build(); } } return new L3AddressBuilder().setL3Context(new L3ContextId(port.getNetworkId().getValue())) .setIpAddress(portFixedIPs.getIpAddress()) .build(); }
private DhcpInfo getDhcpInfo(Port nPort, Subnet nSubnet) { DhcpInfo dhcpInfo = null; if( (nPort != null) && (nSubnet != null) ) { String clientIp = nPort.getFixedIps().get(0).getIpAddress().getIpv4Address().getValue(); String serverIp = nSubnet.getGatewayIp().getIpv4Address().getValue(); List<IpAddress> dnsServers = nSubnet.getDnsNameservers(); dhcpInfo = new DhcpInfo(); dhcpInfo.setClientIp(clientIp).setServerIp(serverIp) .setCidr(nSubnet.getCidr()).setHostRoutes(nSubnet.getHostRoutes()) .setDnsServersIpAddrs(dnsServers).setGatewayIp(serverIp); } else { //FIXME: Delete this test code LOG.error("TestOnly Code"); dhcpInfo = new DhcpInfo(); dhcpInfo.setClientIp("1.1.1.3").setServerIp("1.1.1.1") .setCidr("1.1.1.0/24").addDnsServer("1.1.1.1"); LOG.warn("Failed to get Subnet info for DHCP reply"); } return dhcpInfo; }
private void handleRouterInterfaceRemoved(Port routerPort) { if (routerPort.getDeviceId() != null) { Uuid routerId = new Uuid(routerPort.getDeviceId()); for (FixedIps portIP : routerPort.getFixedIps()) { if (portIP.getIpAddress().getIpv4Address() != null) { Uuid vpnId = NeutronvpnUtils.getVpnForRouter(dataBroker, routerId, true); if(vpnId == null) { vpnId = routerId; } nvpnManager.removeSubnetFromVpn(vpnId, portIP.getSubnetId()); nvpnManager.updateSubnetNodeWithFixedIps(portIP.getSubnetId(), null, null, null, null); nvpnNatManager.handleSubnetsForExternalRouter(routerId, dataBroker); String ipValue = portIP.getIpAddress().getIpv4Address().getValue(); NeutronvpnUtils.removeVpnPortFixedIpToPort(dataBroker, vpnId.getValue(), ipValue); } else { LOG.error("No IPv4 address assigned to port {)", routerPort.getUuid().getValue()); } } } }