NeutronPort ans = new NeutronPort(); for (String field: fields) { if ("id".equals(field)) { ans.setPortUUID(this.getPortUUID()); ans.setNetworkUUID(this.getNetworkUUID()); ans.setName(this.getName()); ans.setAdminStateUp(this.getAdminStateUp()); ans.setStatus(this.getStatus()); ans.setMacAddress(this.getMacAddress()); ans.setFixedIPs(new ArrayList<>(this.getFixedIPs())); ans.setDeviceID(this.getDeviceID()); ans.setDeviceOwner(this.getDeviceOwner()); ans.setTenantID(this.getTenantID()); ans.setSecurityGroups(new ArrayList<>(this.getSecurityGroups())); ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
for (String neutronPortUuid:neutronL3Adapter.getPortCleanupCache().keySet()) { NeutronPort neutronPort = neutronL3Adapter.getPortCleanupCache().get(neutronPortUuid); if (!neutronPort.getDeviceOwner().contains("compute")) { LOG.debug("getVMListForSecurityGroup : the port {} is not " + "compute port belongs to {}", neutronPort.getID(), neutronPort.getDeviceOwner()); continue; if (portUuid.equals(neutronPort.getID())) { continue; List<NeutronSecurityGroup> securityGroups = neutronPort.getSecurityGroups(); if (null != securityGroups) { for (NeutronSecurityGroup securityGroup:securityGroups) { if (securityGroup.getSecurityGroupUUID().equals(securityGroupUuid)) { LOG.debug("getVMListForSecurityGroup : adding ports with ips {} " + "compute port", neutronPort.getFixedIPs()); if (neutronPort.getFixedIPs() != null) { vmListForSecurityGroup.addAll(neutronPort.getFixedIPs());
public NeutronPort createNeutronPort(String networkId, String subnetId, String id, String owner, String ipaddr, String mac, NeutronSecurityGroup... secGroups) { INeutronPortCRUD iNeutronPortCRUD = (INeutronPortCRUD) ServiceHelper.getGlobalInstance(INeutronPortCRUD.class, this); NeutronPort np = new NeutronPort(); np.initDefaults(); np.setID(id); np.setDeviceOwner(owner); np.setMacAddress(mac); np.setNetworkUUID(networkId); List<org.opendaylight.netvirt.openstack.netvirt.translator.Neutron_IPs> srcAddressList = new ArrayList<>(); org.opendaylight.netvirt.openstack.netvirt.translator.Neutron_IPs nip = new org.opendaylight.netvirt.openstack.netvirt.translator.Neutron_IPs(); nip.setIpAddress(ipaddr); nip.setSubnetUUID(subnetId); srcAddressList.add(nip); np.setFixedIPs(srcAddressList); List<NeutronSecurityGroup> nsgs = Arrays.asList(secGroups); np.setSecurityGroups(nsgs); iNeutronPortCRUD.addPort(np); return np; }
NeutronPort result = new NeutronPort(); result.setAdminStateUp(port.isAdminStateUp()); if (port.getAllowedAddressPairs() != null) { List<NeutronPort_AllowedAddressPairs> pairs = new ArrayList<>(); result.setAllowedAddressPairs(pairs); result.setDeviceID(port.getDeviceId()); result.setDeviceOwner(port.getDeviceOwner()); if (port.getExtraDhcpOpts() != null) { List<NeutronPort_ExtraDHCPOption> options = new ArrayList<>(); result.setExtraDHCPOptions(options); result.setFixedIPs(ips); result.setMacAddress(port.getMacAddress().getValue()); result.setName(port.getName()); result.setNetworkUUID(String.valueOf(port.getNetworkId().getValue())); if (port.getSecurityGroups() != null) { Set<NeutronSecurityGroup> allGroups = new HashSet<>(); result.setSecurityGroups(groups); result.setStatus(port.getStatus()); if (port.getTenantId() != null) { result.setTenantID(String.valueOf(port.getTenantId().getValue()).replace("-", "")); result.setPortUUID(String.valueOf(port.getUuid().getValue()));
@Override protected Port toMd(NeutronPort neutronPort) { PortBindingExtensionBuilder bindingBuilder = new PortBindingExtensionBuilder(); if (neutronPort.getBindinghostID() != null) { bindingBuilder.setHostId(neutronPort.getBindinghostID()); if (neutronPort.getVIFDetails() != null) { final Map<String, String> vifDetails = neutronPort.getVIFDetails(); final List<VifDetails> listVifDetail = new ArrayList<VifDetails>(vifDetails.size()); for (final Map.Entry<String, String> vifDetail : vifDetails.entrySet()) { if (neutronPort.getBindingvifType() != null) { bindingBuilder.setVifType(neutronPort.getBindingvifType()); if (neutronPort.getBindingvnicType() != null) { bindingBuilder.setVnicType(neutronPort.getBindingvnicType()); if (neutronPort.getPortSecurityEnabled() != null) { portSecurityBuilder.setPortSecurityEnabled(neutronPort.getPortSecurityEnabled()); bindingBuilder.build()); portBuilder.addAugmentation(PortSecurityExtension.class, portSecurityBuilder.build()); portBuilder.setAdminStateUp(neutronPort.isAdminStateUp()); if(neutronPort.getAllowedAddressPairs() != null) { List<AllowedAddressPairs> listAllowedAddressPairs = new ArrayList<>(); for (NeutronPort_AllowedAddressPairs allowedAddressPairs : neutronPort.getAllowedAddressPairs()) { AllowedAddressPairsBuilder allowedAddressPairsBuilder = new AllowedAddressPairsBuilder(); allowedAddressPairsBuilder.setIpAddress(new IpPrefixOrAddress(allowedAddressPairs.getIpAddress().toCharArray())); if (neutronPort.getDeviceID() != null) {
final String networkUUID = neutronPort.getNetworkUUID(); NeutronNetwork neutronNetwork = neutronNetworkCache.getNetwork(networkUUID); if (null == neutronNetwork) { final String macAddress = neutronPort.getMacAddress(); if (providerSegmentationId == null || providerSegmentationId.isEmpty() || macAddress == null || macAddress.isEmpty()) { String owner = neutronPort.getDeviceOwner(); boolean isDhcpPort = owner != null && owner.equals(DHCP_DEVICE_OWNER); List<Neutron_IPs> fixedIps = neutronPort.getFixedIPs(); if((null == fixedIps || fixedIps.isEmpty()) && actionToPerform == Action.DELETE && isDhcpPort){ fixedIps = dhcpPortIpCache.get(neutronPort.getPortUUID()); if(fixedIps == null) { return; List<Neutron_IPs> network_Ips = neutronPort.getFixedIPs(); for (Node node : nodes) { if (!port.getDeviceOwner().equalsIgnoreCase(ROUTER_INTERFACE_DEVICE_OWNER)) { final String portMacAddress = port.getMacAddress(); if ( null == portMacAddress || portMacAddress.isEmpty()) { continue; for (Neutron_IPs neutronIPAddr : port.getFixedIPs()) { final String portIPAddress = neutronIPAddr.getIpAddress(); if (null == portIPAddress || portIPAddress.isEmpty()) {
NeutronPort neutronPortForFloatIp = null; for (NeutronPort neutronPort : neutronPorts) { if (neutronPort.getDeviceOwner().equals(OWNER_FLOATING_IP) && neutronPort.getDeviceID().equals(neutronFloatingIP.getID())) { neutronPortForFloatIp = neutronPort; break; String floatingIpMac = neutronPortForFloatIp == null ? null : neutronPortForFloatIp.getMacAddress(); String fixedIpAddress = neutronFloatingIP.getFixedIPAddress(); String floatingIpAddress = neutronFloatingIP.getFloatingIPAddress(); neutronNetworkCache.getNetwork(tenantNeutronPort.getNetworkUUID()) : null; String providerSegmentationId = tenantNeutronNetwork != null ? tenantNeutronNetwork.getProviderSegmentationID() : null;
private void doNeutronPortDeleted(NeutronPort neutronPort) { LOG.debug("Handling neutron delete port {}", neutronPort); distributedArpService.handlePortEvent(neutronPort, Action.DELETE); neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.DELETE); //TODO: Need to implement getNodes List<Node> nodes = nodeCacheManager.getNodes(); for (Node node : nodes) { OvsdbTerminationPointAugmentation port = findPortOnNode(node, neutronPort); if (port != null) { LOG.trace("neutronPortDeleted: Delete interface {}", port.getName()); southbound.deleteTerminationPoint(node, port.getName()); break; } } LOG.debug(" PORT delete successful for tenant-id - {}, network-id - {}, port-id - {}", neutronPort.getTenantID(), neutronPort.getNetworkUUID(), neutronPort.getID()); }
private void updateL3ForNeutronPort(final NeutronPort neutronPort, final boolean isDelete) { final String networkUUID = neutronPort.getNetworkUUID(); final String routerMacAddress = networkIdToRouterMacCache.get(networkUUID); if (routerMacAddress.equalsIgnoreCase(neutronPort.getMacAddress())) { return; final String providerSegmentationId = neutronNetwork != null ? neutronNetwork.getProviderSegmentationID() : null; final String tenantMac = neutronPort.getMacAddress(); continue; if (neutronPort.getFixedIPs() == null) { continue; for (Neutron_IPs neutronIP : neutronPort.getFixedIPs()) { final String tenantIpStr = neutronIP.getIpAddress(); if (tenantIpStr.isEmpty()) {
/** * Look up in the NeutronPortsCRUD cache and return the MAC address for a corresponding IP address * @param neutronPortsCache Reference to port cache to get existing port related data. This interface * basically read data from the md-sal data store. * @param subnetID subnet to which given port is attached * @param ipAddr IP address of a member or VM * @return MAC address registered with that IP address */ public static String getMacAddress(INeutronPortCRUD neutronPortsCache, String subnetID, String ipAddr) { if (ipAddr == null || subnetID == null) { return null; } List<NeutronPort> allPorts = neutronPortsCache.getAllPorts(); for (NeutronPort port : allPorts) { List<Neutron_IPs> fixedIPs = port.getFixedIPs(); if (fixedIPs != null && !fixedIPs.isEmpty()) { for (Neutron_IPs ip : fixedIPs) { if (ip.getIpAddress().equals(ipAddr) && ip.getSubnetUUID().equals(subnetID)) { return port.getMacAddress(); } } } } return null; }
List<Neutron_IPs> neutronPortFixedIp = neutronPort.getFixedIPs(); if (null == neutronPortFixedIp || neutronPortFixedIp.isEmpty()) { return false; if (null != portId) { NeutronPort port = neutronPortCache.getPort(portId); if (null != port && !(port.getID().equals(neutronPort.getID())) && port.getDeviceOwner().contains("compute")) { List<Neutron_IPs> portFixedIp = port.getFixedIPs(); if (null == portFixedIp || portFixedIp.isEmpty()) { return false; .equals(neutronPort.getFixedIPs().iterator().next().getSubnetUUID())) { LOG.trace("isLastPortinSubnet: Port is not the only port."); return false;
private Map<String,NeutronPort> getChangedPorts(Map<InstanceIdentifier<?>, DataObject> changedData) { LOG.trace("getChangedPorts:" + changedData); Map<String,NeutronPort> portMap = new HashMap<>(); for (Map.Entry<InstanceIdentifier<?>, DataObject> changed : changedData.entrySet()) { if (changed.getValue() instanceof Port) { NeutronPort port = fromMd((Port)changed.getValue()); portMap.put(port.getID(), port); } } return portMap; }
if (cachedportUuid.equals(port.getID())) { continue; if (port.getFixedIPs() == null) { continue; for (Neutron_IPs vmIp : port.getFixedIPs()) { securityServicesManager.syncSecurityRule(cachedport, securityRule, vmIp, true);
return; NeutronNetwork neutronNetwork = neutronNetworkCache.getNetwork(port.getNetworkUUID()); if (null == neutronNetwork) { neutronNetwork = neutronL3Adapter.getNetworkFromCleanupCache(port.getNetworkUUID()); if (neutronNetwork == null) { return; srcAddressList = this.getIpAddressList(intf); ingressAclProvider.programFixedSecurityGroup(dpid, segmentationId, dhcpPort.getMacAddress(), localPort, attachedMac, write); egressAclProvider.programFixedSecurityGroup(dpid, segmentationId, attachedMac, localPort, srcAddressList, write);
private void updatePort( AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes, Object[] subscribers) { Map<String, NeutronPort> originalPortMap = getChangedPorts(changes.getOriginalData()); for (Entry<InstanceIdentifier<?>, DataObject> updatePort : changes.getUpdatedData().entrySet()) { if (updatePort.getValue() instanceof Port) { NeutronPort port = fromMd((Port)updatePort.getValue()); NeutronPort originalPort = originalPortMap.get(port.getID()); if (originalPort != null) { port.setOriginalPort(originalPort); } else { LOG.warn("Original Port data is missing"); } for (Object entry: subscribers) { INeutronPortAware subscriber = (INeutronPortAware)entry; subscriber.neutronPortUpdated(port); } } } }
private void syncSecurityGroup(NeutronSecurityRule securityRule,NeutronPort port, boolean write) { if (!port.getPortSecurityEnabled()) { LOG.info("Port security not enabled port", port); return; } if (null != securityRule.getSecurityRemoteGroupID()) { List<Neutron_IPs> vmIpList = securityServicesManager .getVmListForSecurityGroup(port.getID(), securityRule.getSecurityRemoteGroupID()); for (Neutron_IPs vmIp :vmIpList ) { securityServicesManager.syncSecurityRule(port, securityRule, vmIp, write); } } else { securityServicesManager.syncSecurityRule(port, securityRule, null, write); } }
private Pair<Long, Uuid> getDpIdOfNeutronPort(String neutronTenantPortUuid) { if(neutronPortToDpIdCache.get(neutronTenantPortUuid) == null) { List<Node> bridges = this.southbound.readOvsdbTopologyBridgeNodes(); LOG.debug("getDpIdOfNeutronPort : {} bridges present in ovsdb topology",bridges.size()); for(Node bridge : bridges) { List<OvsdbTerminationPointAugmentation> interfaces = southbound.extractTerminationPointAugmentations(bridge); if(interfaces != null && !interfaces.isEmpty()) { LOG.debug("getDpIdOfNeutronPort : {} termination point present on bridge {}", interfaces.size(), bridge.getNodeId()); for (OvsdbTerminationPointAugmentation intf : interfaces) { NeutronPort neutronPort = tenantNetworkManager.getTenantPort(intf); if(neutronPort != null && neutronPort.getID().equals(neutronTenantPortUuid)) { Long dpId = getDpidForIntegrationBridge(bridge); Uuid interfaceUuid = intf.getInterfaceUuid(); LOG.debug("getDpIdOfNeutronPort : Found bridge {} and interface {} for the tenant neutron" + " port {}",dpId,interfaceUuid,neutronTenantPortUuid); handleInterfaceEventAdd(neutronPort.getPortUUID(), dpId, interfaceUuid); break; } } } } } return neutronPortToDpIdCache.get(neutronTenantPortUuid); }
private void init() { /* * Rebuild the cache in case of a restart. */ List<NeutronPort> portList = neutronPortCache.getAllPorts(); for (NeutronPort port:portList) { List<NeutronSecurityGroup> securityGroupList = port.getSecurityGroups(); if ( null != securityGroupList) { for (NeutronSecurityGroup securityGroup : securityGroupList) { List<NeutronSecurityRule> securityRuleList = getSecurityRulesforGroup(securityGroup); if ( null != securityRuleList) { for (NeutronSecurityRule securityRule : securityRuleList) { if (null != securityRule.getSecurityRemoteGroupID()) { this.addToCache(securityRule.getSecurityRemoteGroupID(), port.getID()); } } } } } } }
return; ingressAclProvider.programFixedSecurityGroup(dpid, segmentationId, dhcpPort.getMacAddress(), localPort, attachedMac, write); egressAclProvider.programFixedSecurityGroup(dpid, segmentationId, attachedMac, localPort,
protected NeutronPort fromMd(Port port) { NeutronPort result = new NeutronPort(); result.setAdminStateUp(port.isAdminStateUp()); if (port.getAllowedAddressPairs() != null) { List<NeutronPort_AllowedAddressPairs> pairs = new ArrayList<>(); result.setAllowedAddressPairs(pairs); result.setDeviceID(port.getDeviceId()); result.setDeviceOwner(port.getDeviceOwner()); if (port.getExtraDhcpOpts() != null) { List<NeutronPort_ExtraDHCPOption> options = new ArrayList<>(); result.setExtraDHCPOptions(options); result.setFixedIPs(ips); result.setMacAddress(port.getMacAddress().getValue()); result.setName(port.getName()); result.setNetworkUUID(String.valueOf(port.getNetworkId().getValue())); if (port.getSecurityGroups() != null) { Set<NeutronSecurityGroup> allGroups = new HashSet<>(); result.setSecurityGroups(groups); result.setStatus(port.getStatus()); if (port.getTenantId() != null) { result.setTenantID(String.valueOf(port.getTenantId().getValue()).replace("-", "")); result.setPortUUID(String.valueOf(port.getUuid().getValue()));