@Test public void testBuildVhostUserEndpoint_notValidVppEp() { port = TestUtils.createNonVppPort(); thrown.expect(NullPointerException.class); portHandler.buildVppEndpoint(port, bebp); }
@VisibleForTesting VppEndpoint buildVppEndpoint(Port port, BaseEndpointByPort bebp) { PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class); ExcludeFromPolicy excludeFromPolicy = new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build(); VppEndpointBuilder vppEpBuilder = new VppEndpointBuilder().setDescription("neutron port") .setContextId(bebp.getContextId()) .setContextType(bebp.getContextType()) .setAddress(bebp.getAddress()) .setAddressType(bebp.getAddressType()) .setVppInterfaceName(VPP_INTERFACE_NAME_PREFIX + bebp.getPortId().getValue()) .setVppNodeId(new NodeId(portBinding.getHostId())); if (port.getDeviceOwner().contains(COMPUTE_OWNER)) { vppEpBuilder.setInterfaceTypeChoice( new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build()); Optional<PortSecurityExtension> portSecurity = Optional.fromNullable(port.getAugmentation(PortSecurityExtension.class)); if (portSecurity.isPresent() && !portSecurity.get().isPortSecurityEnabled()) { vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } } else if (port.getDeviceOwner().contains(DHCP_OWNER) && port.getMacAddress() != null) { IpAddress dhcpServerIpAddress = port.getFixedIps().stream().findFirst().isPresent() ? port.getFixedIps().stream().findFirst().get().getIpAddress() : null; TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createPortName(port.getUuid())) .setDhcpServerAddress(dhcpServerIpAddress) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); } else if (isValidQRouterPort(port)) { TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createQRouterPortName(port.getUuid())) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } else if (isValidVppRouterPort(port)) { if (!DEFAULT_NODE.equals(routingNode.getValue())) { LOG.warn( "Host-id changed by ODL for port {}. This is a supplementary workaround for choosing a routing node.", port); vppEpBuilder.setVppNodeId(routingNode); } else if (port.getDeviceId() != null) { LOG.debug("Resolving host-id for unbound router port {}", port.getUuid()); Optional<Ports> optPorts = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).child(Ports.class).build()); if (optPorts.isPresent() && optPorts.get().getPort() != null) { java.util.Optional<Port> optPortOnTheSameNode = optPorts.get() .getPort() .stream() .filter(p -> !p.getUuid().equals(port.getUuid())) .filter(p -> p.getAugmentation(PortBindingExtension.class) != null) .filter(p -> p.getDeviceOwner().contains(DHCP_OWNER)) .findFirst(); if (optPortOnTheSameNode.isPresent()) { PortBindingExtension binding = optPortOnTheSameNode.get().getAugmentation(PortBindingExtension.class); if (binding != null && binding.getHostId() != null) { vppEpBuilder.setVppNodeId(new NodeId(binding.getHostId())); } else { LOG.warn("Cannot resolve location of router-port {}", port.getUuid()); return null; } } } } vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); vppEpBuilder.setInterfaceTypeChoice(getLoopbackCase(port)); } return vppEpBuilder.build(); }
PortHandler implements TransactionChainListener { @VisibleForTesting VppEndpoint buildVppEndpoint(Port port, BaseEndpointByPort bebp) { PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class); ExcludeFromPolicy excludeFromPolicy = new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build(); VppEndpointBuilder vppEpBuilder = new VppEndpointBuilder().setDescription("neutron port") .setContextId(bebp.getContextId()) .setContextType(bebp.getContextType()) .setAddress(bebp.getAddress()) .setAddressType(bebp.getAddressType()) .setVppInterfaceName(VPP_INTERFACE_NAME_PREFIX + bebp.getPortId().getValue()) .setVppNodeId(new NodeId(portBinding.getHostId())); if (port.getDeviceOwner().contains(COMPUTE_OWNER)) { vppEpBuilder.setInterfaceTypeChoice( new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build()); Optional<PortSecurityExtension> portSecurity = Optional.fromNullable(port.getAugmentation(PortSecurityExtension.class)); if (portSecurity.isPresent() && !portSecurity.get().isPortSecurityEnabled()) { vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } } else if (port.getDeviceOwner().contains(DHCP_OWNER) && port.getMacAddress() != null) { IpAddress dhcpServerIpAddress = port.getFixedIps().stream().findFirst().isPresent() ? port.getFixedIps().stream().findFirst().get().getIpAddress() : null; TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createPortName(port.getUuid())) .setDhcpServerAddress(dhcpServerIpAddress) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); } else if (isValidQRouterPort(port)) { TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createQRouterPortName(port.getUuid())) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } else if (isValidVppRouterPort(port)) { if (!DEFAULT_NODE.equals(routingNode.getValue())) { LOG.warn( "Host-id changed by ODL for port {}. This is a supplementary workaround for choosing a routing node.", port); vppEpBuilder.setVppNodeId(routingNode); } else if (port.getDeviceId() != null) { LOG.debug("Resolving host-id for unbound router port {}", port.getUuid()); Optional<Ports> optPorts = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).child(Ports.class).build()); if (optPorts.isPresent() && optPorts.get().getPort() != null) { java.util.Optional<Port> optPortOnTheSameNode = optPorts.get() .getPort() .stream() .filter(p -> !p.getUuid().equals(port.getUuid())) .filter(p -> p.getAugmentation(PortBindingExtension.class) != null) .filter(p -> p.getDeviceOwner().contains(DHCP_OWNER)) .findFirst(); if (optPortOnTheSameNode.isPresent()) { PortBindingExtension binding = optPortOnTheSameNode.get().getAugmentation(PortBindingExtension.class); if (binding != null && binding.getHostId() != null) { vppEpBuilder.setVppNodeId(new NodeId(binding.getHostId())); } else { LOG.warn("Cannot resolve location of router-port {}", port.getUuid()); return null; } } } } vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); vppEpBuilder.setInterfaceTypeChoice(getLoopbackCase(port)); } return vppEpBuilder.build(); } }
PortHandler implements TransactionChainListener { @VisibleForTesting VppEndpoint buildVppEndpoint(Port port, BaseEndpointByPort bebp) { PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class); ExcludeFromPolicy excludeFromPolicy = new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build(); VppEndpointBuilder vppEpBuilder = new VppEndpointBuilder().setDescription("neutron port") .setContextId(bebp.getContextId()) .setContextType(bebp.getContextType()) .setAddress(bebp.getAddress()) .setAddressType(bebp.getAddressType()) .setVppInterfaceName(VPP_INTERFACE_NAME_PREFIX + bebp.getPortId().getValue()) .setVppNodeId(new NodeId(portBinding.getHostId())); if (port.getDeviceOwner().contains(COMPUTE_OWNER)) { vppEpBuilder.setInterfaceTypeChoice( new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build()); Optional<PortSecurityExtension> portSecurity = Optional.fromNullable(port.getAugmentation(PortSecurityExtension.class)); if (portSecurity.isPresent() && !portSecurity.get().isPortSecurityEnabled()) { vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } } else if (port.getDeviceOwner().contains(DHCP_OWNER) && port.getMacAddress() != null) { IpAddress dhcpServerIpAddress = port.getFixedIps().stream().findFirst().isPresent() ? port.getFixedIps().stream().findFirst().get().getIpAddress() : null; TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createPortName(port.getUuid())) .setDhcpServerAddress(dhcpServerIpAddress) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); } else if (isValidQRouterPort(port)) { TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createQRouterPortName(port.getUuid())) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } else if (isValidVppRouterPort(port)) { if (!DEFAULT_NODE.equals(routingNode.getValue())) { LOG.warn( "Host-id changed by ODL for port {}. This is a supplementary workaround for choosing a routing node.", port); vppEpBuilder.setVppNodeId(routingNode); } else if (port.getDeviceId() != null) { LOG.debug("Resolving host-id for unbound router port {}", port.getUuid()); Optional<Ports> optPorts = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).child(Ports.class).build()); if (optPorts.isPresent() && optPorts.get().getPort() != null) { java.util.Optional<Port> optPortOnTheSameNode = optPorts.get() .getPort() .stream() .filter(p -> !p.getUuid().equals(port.getUuid())) .filter(p -> p.getAugmentation(PortBindingExtension.class) != null) .filter(p -> p.getDeviceOwner().contains(DHCP_OWNER)) .findFirst(); if (optPortOnTheSameNode.isPresent()) { PortBindingExtension binding = optPortOnTheSameNode.get().getAugmentation(PortBindingExtension.class); if (binding != null && binding.getHostId() != null) { vppEpBuilder.setVppNodeId(new NodeId(binding.getHostId())); } else { LOG.warn("Cannot resolve location of router-port {}", port.getUuid()); return null; } } } } vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); vppEpBuilder.setInterfaceTypeChoice(getLoopbackCase(port)); } return vppEpBuilder.build(); } PortHandler(DataBroker dataBroker, NodeId routingNodeId); }
PortHandler implements TransactionChainListener { @VisibleForTesting VppEndpoint buildVppEndpoint(Port port, BaseEndpointByPort bebp) { PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class); ExcludeFromPolicy excludeFromPolicy = new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build(); VppEndpointBuilder vppEpBuilder = new VppEndpointBuilder().setDescription("neutron port") .setContextId(bebp.getContextId()) .setContextType(bebp.getContextType()) .setAddress(bebp.getAddress()) .setAddressType(bebp.getAddressType()) .setVppInterfaceName(VPP_INTERFACE_NAME_PREFIX + bebp.getPortId().getValue()) .setVppNodeId(new NodeId(portBinding.getHostId())); if (port.getDeviceOwner().contains(COMPUTE_OWNER)) { vppEpBuilder.setInterfaceTypeChoice( new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build()); Optional<PortSecurityExtension> portSecurity = Optional.fromNullable(port.getAugmentation(PortSecurityExtension.class)); if (portSecurity.isPresent() && !portSecurity.get().isPortSecurityEnabled()) { vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } } else if (port.getDeviceOwner().contains(DHCP_OWNER) && port.getMacAddress() != null) { IpAddress dhcpServerIpAddress = port.getFixedIps().stream().findFirst().isPresent() ? port.getFixedIps().stream().findFirst().get().getIpAddress() : null; TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createPortName(port.getUuid())) .setDhcpServerAddress(dhcpServerIpAddress) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); } else if (isValidQRouterPort(port)) { TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createQRouterPortName(port.getUuid())) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } else if (isValidVppRouterPort(port)) { if (!DEFAULT_NODE.equals(routingNode.getValue())) { LOG.warn( "Host-id changed by ODL for port {}. This is a supplementary workaround for choosing a routing node.", port); vppEpBuilder.setVppNodeId(routingNode); } else if (port.getDeviceId() != null) { LOG.debug("Resolving host-id for unbound router port {}", port.getUuid()); Optional<Ports> optPorts = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).child(Ports.class).build()); if (optPorts.isPresent() && optPorts.get().getPort() != null) { java.util.Optional<Port> optPortOnTheSameNode = optPorts.get() .getPort() .stream() .filter(p -> !p.getUuid().equals(port.getUuid())) .filter(p -> p.getAugmentation(PortBindingExtension.class) != null) .filter(p -> p.getDeviceOwner().contains(DHCP_OWNER)) .findFirst(); if (optPortOnTheSameNode.isPresent()) { PortBindingExtension binding = optPortOnTheSameNode.get().getAugmentation(PortBindingExtension.class); if (binding != null && binding.getHostId() != null) { vppEpBuilder.setVppNodeId(new NodeId(binding.getHostId())); } else { LOG.warn("Cannot resolve location of router-port {}", port.getUuid()); return null; } } } } vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); vppEpBuilder.setInterfaceTypeChoice(getLoopbackCase(port)); } return vppEpBuilder.build(); } PortHandler(DataBroker dataBroker, NodeId routingNodeId); static Optional<FixedIps> resolveFirstFixedIps(Port port); @Override void onTransactionChainFailed(TransactionChain<?, ?> chain, AsyncTransaction<?, ?> transaction,
            Throwable cause); @Override void onTransactionChainSuccessful(TransactionChain<?, ?> chain); }
PortHandler implements TransactionChainListener { @VisibleForTesting VppEndpoint buildVppEndpoint(Port port, BaseEndpointByPort bebp) { PortBindingExtension portBinding = port.getAugmentation(PortBindingExtension.class); ExcludeFromPolicy excludeFromPolicy = new ExcludeFromPolicyBuilder().setExcludeFromPolicy(true).build(); VppEndpointBuilder vppEpBuilder = new VppEndpointBuilder().setDescription("neutron port") .setContextId(bebp.getContextId()) .setContextType(bebp.getContextType()) .setAddress(bebp.getAddress()) .setAddressType(bebp.getAddressType()) .setVppInterfaceName(VPP_INTERFACE_NAME_PREFIX + bebp.getPortId().getValue()) .setVppNodeId(new NodeId(portBinding.getHostId())); if (port.getDeviceOwner().contains(COMPUTE_OWNER)) { vppEpBuilder.setInterfaceTypeChoice( new VhostUserCaseBuilder().setSocket(getSocketFromPortBinding(portBinding)).build()); Optional<PortSecurityExtension> portSecurity = Optional.fromNullable(port.getAugmentation(PortSecurityExtension.class)); if (portSecurity.isPresent() && !portSecurity.get().isPortSecurityEnabled()) { vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } } else if (port.getDeviceOwner().contains(DHCP_OWNER) && port.getMacAddress() != null) { IpAddress dhcpServerIpAddress = port.getFixedIps().stream().findFirst().isPresent() ? port.getFixedIps().stream().findFirst().get().getIpAddress() : null; TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createPortName(port.getUuid())) .setDhcpServerAddress(dhcpServerIpAddress) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); } else if (isValidQRouterPort(port)) { TapCase tapCase = new TapCaseBuilder().setPhysicalAddress(new PhysAddress(port.getMacAddress().getValue())) .setName(createQRouterPortName(port.getUuid())) .build(); vppEpBuilder.setInterfaceTypeChoice(tapCase); vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); } else if (isValidVppRouterPort(port)) { if (!DEFAULT_NODE.equals(routingNode.getValue())) { LOG.warn( "Host-id changed by ODL for port {}. This is a supplementary workaround for choosing a routing node.", port); vppEpBuilder.setVppNodeId(routingNode); } else if (port.getDeviceId() != null) { LOG.debug("Resolving host-id for unbound router port {}", port.getUuid()); Optional<Ports> optPorts = syncedChain.readFromDs(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).child(Ports.class).build()); if (optPorts.isPresent() && optPorts.get().getPort() != null) { java.util.Optional<Port> optPortOnTheSameNode = optPorts.get() .getPort() .stream() .filter(p -> !p.getUuid().equals(port.getUuid())) .filter(p -> p.getAugmentation(PortBindingExtension.class) != null) .filter(p -> p.getDeviceOwner().contains(DHCP_OWNER)) .findFirst(); if (optPortOnTheSameNode.isPresent()) { PortBindingExtension binding = optPortOnTheSameNode.get().getAugmentation(PortBindingExtension.class); if (binding != null && binding.getHostId() != null) { vppEpBuilder.setVppNodeId(new NodeId(binding.getHostId())); } else { LOG.warn("Cannot resolve location of router-port {}", port.getUuid()); return null; } } } } vppEpBuilder.addAugmentation(ExcludeFromPolicy.class, excludeFromPolicy); vppEpBuilder.setInterfaceTypeChoice(getLoopbackCase(port)); } return vppEpBuilder.build(); } PortHandler(DataBroker dataBroker, NodeId routingNodeId); static Optional<FixedIps> resolveFirstFixedIps(Port port); @Override void onTransactionChainFailed(TransactionChain<?, ?> chain, AsyncTransaction<?, ?> transaction,
            Throwable cause); @Override void onTransactionChainSuccessful(TransactionChain<?, ?> chain);  }