NeutronPortChangeListener extends AbstractAsyncDataTreeChangeListener<Port> { @Override public void add(InstanceIdentifier<Port> identifier, Port input) { LOG.trace("Received port add event: port={}", input); String portName = input.getUuid().getValue(); LOG.trace("Adding Port : key: {}, value={}", identifier, input); Network network = neutronvpnUtils.getNeutronNetwork(input.getNetworkId()); if (network == null || !NeutronvpnUtils.isNetworkTypeSupported(network)) { LOG.warn("neutron vpn received a port add() for a network without a provider extension augmentation " + "or with an unsupported network type for the port {} which is part of network {}", portName, network); return; } neutronvpnUtils.addToPortCache(input); String portStatus = NeutronUtils.PORT_STATUS_DOWN; if (!Strings.isNullOrEmpty(input.getDeviceOwner()) && !Strings.isNullOrEmpty(input.getDeviceId())) { if (NeutronConstants.DEVICE_OWNER_ROUTER_INF.equals(input.getDeviceOwner())) { handleRouterInterfaceAdded(input); NeutronUtils.createPortStatus(input.getUuid().getValue(), NeutronUtils.PORT_STATUS_ACTIVE, dataBroker); return; } if (NeutronConstants.DEVICE_OWNER_GATEWAY_INF.equals(input.getDeviceOwner())) { handleRouterGatewayUpdated(input, false); portStatus = NeutronUtils.PORT_STATUS_ACTIVE; } else if (NeutronConstants.DEVICE_OWNER_FLOATING_IP.equals(input.getDeviceOwner())) { handleFloatingIpPortUpdated(null, input); portStatus = NeutronUtils.PORT_STATUS_ACTIVE; } } if (input.getFixedIps() != null && !input.getFixedIps().isEmpty() && !(isPortTypeSwitchdev(input) && !isPortBound(input))) { handleNeutronPortCreated(input); } NeutronUtils.createPortStatus(input.getUuid().getValue(), portStatus, dataBroker); } @Inject  NeutronPortChangeListener(final DataBroker dataBroker,
                                     final NeutronvpnManager neutronvpnManager,
                                     final NeutronvpnNatManager neutronvpnNatManager,
                                     final NeutronSubnetGwMacResolver gwMacResolver,
                                     final IElanService elanService,
                                     final JobCoordinator jobCoordinator,
                                     final NeutronvpnUtils neutronvpnUtils,
                                     final HostConfigCache hostConfigCache,
                                     final DataTreeEventCallbackRegistrar dataTreeEventCallbackRegistrar,
                                     final NeutronvpnConfig neutronvpnConfig); void init(); @Override @PreDestroy void close(); @Override void add(InstanceIdentifier<Port> identifier, Port input); @Override void remove(InstanceIdentifier<Port> identifier, Port input); @Override void update(InstanceIdentifier<Port> identifier, Port original, Port update);  }
@Test public void addPort__Ipv6FixedIps() throws Exception { PortBuilder pb = new PortBuilder(); pb.setUuid(new Uuid("12345678-1234-1234-1234-123456789012")); pb.setNetworkId(new Uuid("12345678-1234-1234-1234-123456789012")); pb.setMacAddress(new MacAddress("AA:BB:CC:DD:EE:FF")); IpAddress ipv6 = new IpAddress(new Ipv6Address("1::1")); FixedIpsBuilder fib = new FixedIpsBuilder(); fib.setIpAddress(ipv6); List<FixedIps> fixedIps = new ArrayList<>(); fixedIps.add(fib.build()); pb.setFixedIps(fixedIps); Port port = pb.build(); neutronPortChangeListener.add(InstanceIdentifier.create(Port.class), port); }
@Test public void addPort__Ipv4FixedIps() throws Exception { PortBuilder pb = new PortBuilder(); pb.setUuid(new Uuid("12345678-1234-1234-1234-123456789012")); pb.setNetworkId(new Uuid("12345678-1234-1234-1234-123456789012")); pb.setMacAddress(new MacAddress("AA:BB:CC:DD:EE:FF")); IpAddress ipv4 = new IpAddress(new Ipv4Address("2.2.2.2")); FixedIpsBuilder fib = new FixedIpsBuilder(); fib.setIpAddress(ipv4); List<FixedIps> fixedIps = new ArrayList<>(); fixedIps.add(fib.build()); pb.setFixedIps(fixedIps); Port port = pb.build(); neutronPortChangeListener.add(InstanceIdentifier.create(Port.class), port); }
@Test public void addPort__NoFixedIps() throws Exception { PortBuilder pb = new PortBuilder(); pb.setUuid(new Uuid("12345678-1234-1234-1234-123456789012")); pb.setNetworkId(new Uuid("12345678-1234-1234-1234-123456789012")); pb.setMacAddress(new MacAddress("AA:BB:CC:DD:EE:FF")); List<FixedIps> fixedIps = new ArrayList<>(); pb.setFixedIps(fixedIps); Port port = pb.build(); neutronPortChangeListener.add(InstanceIdentifier.create(Port.class), port); }