@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()); } } }
/** * Is port_security_enabled with the port. * * @param port the port * @return whether port_security_enabled is set to TRUE */ protected static boolean isPortSecurityEnabled(Port port) { PortSecurityExtension portSecurity = port.getAugmentation(PortSecurityExtension.class); return portSecurity != null && portSecurity.isPortSecurityEnabled() != null; }
@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); } }
@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 static boolean isQrouterPort(Port port) { return DEVICE_OWNER_ROUTER_IFACE.equals(port.getDeviceOwner()) && port.getAugmentation(PortBindingExtension.class) != null && DEVICE_VIF_TYPE.equals(port.getAugmentation(PortBindingExtension.class).getVifType()); }
@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()); } }
result.setAdminStateUp(port.isAdminStateUp()); if (port.getAllowedAddressPairs() != null) { List<NeutronPort_AllowedAddressPairs> pairs = new ArrayList<>(); for (AllowedAddressPairs mdPair : port.getAllowedAddressPairs()) { NeutronPort_AllowedAddressPairs pair = new NeutronPort_AllowedAddressPairs(); pair.setIpAddress(mdPair.getIpAddress()); result.setDeviceID(port.getDeviceId()); result.setDeviceOwner(port.getDeviceOwner()); if (port.getExtraDhcpOpts() != null) { List<NeutronPort_ExtraDHCPOption> options = new ArrayList<>(); for (ExtraDhcpOpts opt : port.getExtraDhcpOpts()) { NeutronPort_ExtraDHCPOption arg = new NeutronPort_ExtraDHCPOption(); arg.setName(opt.getOptName()); if (port.getFixedIps() != null) { List<Neutron_IPs> ips = new ArrayList<>(); for (FixedIps mdIP : port.getFixedIps()) { Neutron_IPs ip = new Neutron_IPs(); ip.setIpAddress(String.valueOf(mdIP.getIpAddress().getValue())); result.setMacAddress(port.getMacAddress()); result.setName(port.getName()); result.setNetworkUUID(String.valueOf(port.getNetworkId().getValue())); if (port.getSecurityGroups() != null) { Set<NeutronSecurityGroup> allGroups = new HashSet<>(); NeutronCRUDInterfaces interfaces = new NeutronCRUDInterfaces().fetchINeutronSecurityGroupCRUD(this); INeutronSecurityGroupCRUD sgIf = interfaces.getSecurityGroupInterface(); for (Uuid sgUuid : port.getSecurityGroups()) {
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); } }
/** * 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); }
LOG.trace("created port - {}", port); if (PortUtils.isRouterInterfacePort(port)) { LOG.trace("Port is router interface port: {}", port.getUuid().getValue()); ContextId routerL3Context = new ContextId(port.getDeviceId()); TenantId tenantId = new TenantId(port.getTenantId().getValue()); Optional<Subnet> potentialRouterPortSubnet = SubnetUtils.findSubnet(portIpWithSubnet.getSubnetId(), neutron.getSubnets()); if (!potentialRouterPortSubnet.isPresent()) { AddressEndpointKey addrEpKey = new AddressEndpointKey(port.getMacAddress().getValue(), MacAddressType.class, new ContextId(port.getNetworkId().getValue()), MappingUtils.L2_BRDIGE_DOMAIN); UniqueId portId = new UniqueId(port.getUuid().getValue()); addBaseEndpointMappings(addrEpKey, portId, rwTx); if (port.getAugmentation(PortBindingExtension.class) != null && PortUtils.DEVICE_VIF_TYPE.equals(port.getAugmentation(PortBindingExtension.class).getVifType())) { LOG.trace("Port is QRouter port: {}", port.getUuid().getValue()); Optional<FixedIps> firstFixedIps = PortUtils.resolveFirstFixedIps(port); if (!firstFixedIps.isPresent()) { List<EndpointGroupId> epgsFromSecGroups = resolveEpgIdsFromSecGroups(port.getSecurityGroups()); epgsFromSecGroups.add(NetworkService.EPG_ID); LOG.trace("Port is DHCP port: {}", port.getUuid().getValue()); Optional<FixedIps> firstFixedIps = PortUtils.resolveFirstFixedIps(port); if (!firstFixedIps.isPresent()) { List<EndpointGroupId> epgsFromSecGroups = resolveEpgIdsFromSecGroups(port.getSecurityGroups());
if (ports.isPresent() && ports.get().getPort() != null) { for (Port port : ports.get().getPort()) { List<FixedIps> fixedIPs = port.getFixedIps(); try { if (fixedIPs != null && !fixedIPs.isEmpty()) { result.add(String.format(" %-36s %-19s %-13s %-20s ", port.getUuid().getValue(), port .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.error("Failed to retrieve neutronPorts info for port {}: ", port.getUuid().getValue(), e); System.out.println("Failed to retrieve neutronPorts info for port: " + port.getUuid() .getValue() + ": " + e.getMessage());
private void handleNeutronPortCreated(Port port) { if (!NeutronUtils.isPortVnicTypeNormal(port)) { nvpnManager.updateSubnetmapNodeWithPorts(port.getFixedIps().get(0).getSubnetId(), null, port.getUuid()); LOG.info("Port {} is not a NORMAL VNIC Type port; OF Port interfaces are not created", port.getUuid().getValue()); return; } LOG.info("Of-port-interface creation"); // Create of-port interface for this neutron port String portInterfaceName = createOfPortInterface(port); LOG.debug("Creating ELAN Interface"); createElanInterface(port, portInterfaceName); LOG.debug("Add port to subnet"); // add port to local Subnets DS Uuid vpnId = addPortToSubnets(port); if (vpnId != null) { // create vpn-interface on this neutron port LOG.debug("Adding VPN Interface"); nvpnManager.createVpnInterface(vpnId, port); Uuid routerId = NeutronvpnUtils.getVpnMap(dataBroker, vpnId).getRouterId(); if(routerId != null) { nvpnManager.addToNeutronRouterInterfacesMap(routerId, port.getUuid().getValue()); } } }
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()); } }
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; }
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 void addToPortCache(Port port) { portMap.put(port.getUuid(), port); }
Subnetmap subnetmap = null; boolean isLockAcquired = false; String lockName = port.getUuid().getValue(); String elanInstanceName = port.getNetworkId().getValue(); InstanceIdentifier<ElanInstance> elanIdentifierId = InstanceIdentifier.builder(ElanInstances.class).child (ElanInstance.class, new ElanInstanceKey(elanInstanceName)).build(); FixedIps ip = port.getFixedIps().get(0); subnetId = ip.getSubnetId(); subnetmap = nvpnManager.removePortsFromSubnetmapNode(subnetId, port.getUuid(), null); if (subnetmap != null) { vpnId = subnetmap.getVpnId(); try { isLockAcquired = NeutronvpnUtils.lock(lockManager, lockName); checkAndPublishPortRemoveNotification(subnetmap.getSubnetIp(), subnetId, port.getUuid(), elanTag); LOG.debug("Port removed from subnet notification sent"); } catch (Exception e) {
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()); } } } }
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); }
private AddressEndpointRegBuilder createBasicL3AddrEpInputBuilder(Port port, NetworkDomainId networkContainment, @Nullable List<EndpointGroupId> endpointGroupsToAdd, Neutron neutron) { Optional<FixedIps> firstFixedIps = PortUtils.resolveFirstFixedIps(port); if (!firstFixedIps.isPresent()) { throw new IllegalStateException("Failed to resolve FixedIps for port " + port.getKey() + ". Cannot register L3 Address endpoint."); } ContextId resolveL3ContextForPort = resolveL3ContextForPort(port, port.getFixedIps().get(0), neutron); AddressEndpointRegBuilder addrEpbuilder = new AddressEndpointRegBuilder().setAddressType(MacAddressType.class) .setAddress(MappingUtils.ipAddressToStringIpPrefix(firstFixedIps.get().getIpAddress())) .setAddressType(IpPrefixType.class) .setContextType(MappingUtils.L3_CONTEXT) .setContextId(resolveL3ContextForPort) .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; }