Search in sources :

Example 6 with IP

use of org.openstack4j.model.network.IP in project so by onap.

the class HeatBridgeImplTest method testUpdateLInterfaceVlan.

@Test
public void testUpdateLInterfaceVlan() throws HeatBridgeException {
    // Arrange
    List<Resource> stackResources = (List<Resource>) extractTestStackResources();
    Port port = mock(Port.class);
    when(port.getId()).thenReturn("test-port-id");
    when(port.getName()).thenReturn("test-port-name");
    when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
    when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
    when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
    when(port.getDeviceId()).thenReturn("test-device-id");
    LInterface lIf = new LInterface();
    lIf.setInterfaceId("test-port-id");
    lIf.setInterfaceType("SRIOV");
    lIf.setInterfaceName("name");
    String pfPciId = "0000:08:00.0";
    when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id"));
    IP ip = mock(IP.class);
    Set<IP> ipSet = new HashSet<>();
    ipSet.add(ip);
    when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226");
    when(ip.getSubnetId()).thenReturn("testSubnetId");
    when(port.getFixedIps()).thenAnswer(x -> ipSet);
    Subnet subnet = mock(Subnet.class);
    when(subnet.getCidr()).thenReturn("169.254.100.0/24");
    when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet);
    Network network = mock(Network.class);
    when(network.getId()).thenReturn("test-network-id");
    when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
    when(network.getProviderSegID()).thenReturn("2345");
    when(network.getProviderPhyNet()).thenReturn("ovsnet");
    doNothing().when(heatbridge).processOVS(any(), any(), any());
    when(osClient.getNetworkById(anyString())).thenReturn(network);
    SriovPf sriovPf = new SriovPf();
    sriovPf.setPfPciId(pfPciId);
    PInterface pIf = mock(PInterface.class);
    when(pIf.getInterfaceName()).thenReturn("test-port-id");
    when(resourcesClient.get(eq(PInterface.class), any(AAIResourceUri.class))).thenReturn(Optional.of(pIf));
    // Act
    heatbridge.createVlanAndSriovVF(port, lIf, "hostname");
    // Assert
    verify(transaction, times(2)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
    verify(osClient, times(1)).getNetworkById(anyString());
    verify(heatbridge, times(0)).processOVS(any(), any(), any());
}
Also used : Optional(java.util.Optional) Port(org.openstack4j.model.network.Port) IP(org.openstack4j.model.network.IP) Resource(org.openstack4j.model.heat.Resource) HeatResource(org.openstack4j.openstack.heat.domain.HeatResource) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SriovPf(org.onap.aai.domain.yang.SriovPf) PInterface(org.onap.aai.domain.yang.PInterface) Network(org.openstack4j.model.network.Network) LInterface(org.onap.aai.domain.yang.LInterface) List(java.util.List) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) Subnet(org.openstack4j.model.network.Subnet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with IP

use of org.openstack4j.model.network.IP in project so by onap.

the class HeatBridgeImplTest method testUpdateLInterfaceIps.

@Test
public void testUpdateLInterfaceIps() throws HeatBridgeException, JsonParseException, JsonMappingException, IOException {
    Port port = mock(Port.class);
    when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
    when(port.getDeviceId()).thenReturn("test-device-id");
    IP ip = mock(IP.class);
    Set<IP> ipSet = new HashSet<>();
    ipSet.add(ip);
    when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226");
    when(ip.getSubnetId()).thenReturn("testSubnetId");
    when(port.getFixedIps()).thenAnswer(x -> ipSet);
    Subnet subnet = mock(Subnet.class);
    when(subnet.getCidr()).thenReturn("169.254.100.0/24");
    when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet);
    LInterface lIf = new LInterface();
    lIf.setInterfaceName("test-port-name");
    // Act
    heatbridge.updateLInterfaceIps(port, lIf);
    L3InterfaceIpv6AddressList ipv6 = new L3InterfaceIpv6AddressList();
    ipv6.setIsFloating(false);
    ipv6.setL3InterfaceIpv6Address("2606:ae00:2e60:100::226");
    ipv6.setNeutronNetworkId(port.getNetworkId());
    ipv6.setNeutronSubnetId(ip.getSubnetId());
    ipv6.setL3InterfaceIpv6PrefixLength(Long.parseLong("24"));
    ArgumentCaptor<Optional> argument = ArgumentCaptor.forClass(Optional.class);
    // Assert
    verify(transaction).createIfNotExists(eq(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion("CloudOwner", "RegionOne").tenant("7320ec4a5b9d4589ba7c4412ccfd290f").vserver("test-device-id").lInterface("test-port-name").l3InterfaceIpv6AddressList("2606:ae00:2e60:100::226"))), argument.capture());
    assertTrue(argument.getValue().isPresent());
    assertThat((L3InterfaceIpv6AddressList) argument.getValue().get(), sameBeanAs(ipv6));
}
Also used : Optional(java.util.Optional) Port(org.openstack4j.model.network.Port) IP(org.openstack4j.model.network.IP) LInterface(org.onap.aai.domain.yang.LInterface) Subnet(org.openstack4j.model.network.Subnet) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with IP

use of org.openstack4j.model.network.IP in project so by onap.

the class HeatBridgeImplTest method testUpdateVserverLInterfacesToAai.

@Test
public void testUpdateVserverLInterfacesToAai() throws HeatBridgeException, JsonParseException, JsonMappingException, IOException {
    // Arrange
    List<Resource> stackResources = (List<Resource>) extractTestStackResources();
    Port port = mock(Port.class);
    when(port.getId()).thenReturn("test-port-id");
    when(port.getHostId()).thenReturn("pserverId");
    when(port.getName()).thenReturn("test-port-name");
    when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
    when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
    when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
    when(port.getDeviceId()).thenReturn("test-device-id");
    when(osClient.getServerById("test-device-id")).thenReturn(server);
    when(server.getHypervisorHostname()).thenReturn("test.server.name");
    String pfPciId = "0000:08:00.0";
    when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, HeatBridgeConstants.OS_PF_PCI_SLOT_KEY, "testPfPciId"));
    IP ip = mock(IP.class);
    Set<IP> ipSet = new HashSet<>();
    ipSet.add(ip);
    when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226");
    when(ip.getSubnetId()).thenReturn("testSubnetId");
    when(port.getFixedIps()).thenAnswer(x -> ipSet);
    Subnet subnet = mock(Subnet.class);
    when(subnet.getCidr()).thenReturn("169.254.100.0/24");
    when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet);
    Network network = mock(Network.class);
    when(network.getId()).thenReturn("test-network-id");
    when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
    when(network.getProviderSegID()).thenReturn("2345");
    when(network.getProviderPhyNet()).thenReturn("ovsnet");
    when(osClient.getPortById("212a203a-9764-4f42-84ea-731536a8f13a")).thenReturn(port);
    when(osClient.getPortById("387e3904-8948-43d1-8635-b6c2042b54da")).thenReturn(port);
    when(osClient.getPortById("70a09dfd-f1c5-4bc8-bd8f-dc539b8d662a")).thenReturn(port);
    when(osClient.getPortById("12f88b4d-c8a4-4fbd-bcb4-7e36af02430b")).thenReturn(port);
    when(osClient.getPortById("c54b9f45-b413-4937-bbe4-3c8a5689cfc9")).thenReturn(port);
    when(osClient.getNetworkById(anyString())).thenReturn(network);
    SriovPf sriovPf = new SriovPf();
    sriovPf.setPfPciId(pfPciId);
    when(resourcesClient.exists(any(AAIResourceUri.class))).thenReturn(true);
    when(env.getProperty("mso.cloudOwner.included", "")).thenReturn("CloudOwner");
    doReturn(dSLQueryClient).when(heatbridge).getAAIDSLClient();
    List<Pathed> pathed = ((Results<Pathed>) MAPPER.readValue(getJson("pathed-sriov-pf.json"), new TypeReference<Results<Pathed>>() {
    })).getResult();
    when(dSLQueryClient.queryPathed(any(DSLQuery.class))).thenReturn(pathed);
    doReturn(false).when(heatbridge).sriovVfHasSriovPfRelationship(any());
    // Act
    heatbridge.buildAddVserverLInterfacesToAaiAction(stackResources, Arrays.asList("1", "2"), "CloudOwner");
    // Assert
    verify(transaction, times(20)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
    verify(osClient, times(5)).getPortById(anyString());
    verify(osClient, times(5)).getSubnetById("testSubnetId");
    verify(osClient, times(10)).getNetworkById(anyString());
    verify(transaction, times(5)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
}
Also used : Optional(java.util.Optional) Port(org.openstack4j.model.network.Port) IP(org.openstack4j.model.network.IP) Resource(org.openstack4j.model.heat.Resource) HeatResource(org.openstack4j.openstack.heat.domain.HeatResource) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SriovPf(org.onap.aai.domain.yang.SriovPf) Pathed(org.onap.aaiclient.client.graphinventory.entities.Pathed) Results(org.onap.aaiclient.client.aai.entities.Results) Network(org.openstack4j.model.network.Network) List(java.util.List) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) DSLQuery(org.onap.aaiclient.client.graphinventory.entities.DSLQuery) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Subnet(org.openstack4j.model.network.Subnet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with IP

use of org.openstack4j.model.network.IP in project so by onap.

the class HeatBridgeImpl method updateLInterfaceIps.

protected void updateLInterfaceIps(final Port port, final LInterface lIf) {
    for (IP ip : port.getFixedIps()) {
        String ipAddress = ip.getIpAddress();
        if (InetAddressValidator.getInstance().isValidInet4Address(ipAddress)) {
            Subnet subnet = osClient.getSubnetById(ip.getSubnetId());
            IPAddressString cidr = new IPAddressString(subnet.getCidr());
            L3InterfaceIpv4AddressList lInterfaceIp = new L3InterfaceIpv4AddressList();
            lInterfaceIp.setIsFloating(false);
            lInterfaceIp.setL3InterfaceIpv4Address(ipAddress);
            lInterfaceIp.setNeutronNetworkId(port.getNetworkId());
            lInterfaceIp.setNeutronSubnetId(ip.getSubnetId());
            lInterfaceIp.setL3InterfaceIpv4PrefixLength(Long.parseLong(cidr.getNetworkPrefixLength().toString()));
            transaction.createIfNotExists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).l3InterfaceIpv4AddressList(ipAddress)), Optional.of(lInterfaceIp));
        } else if (InetAddressValidator.getInstance().isValidInet6Address(ipAddress)) {
            Subnet subnet = osClient.getSubnetById(ip.getSubnetId());
            IPAddressString cidr = new IPAddressString(subnet.getCidr());
            L3InterfaceIpv6AddressList ipv6 = new L3InterfaceIpv6AddressList();
            ipv6.setIsFloating(false);
            ipv6.setL3InterfaceIpv6Address(ipAddress);
            ipv6.setNeutronNetworkId(port.getNetworkId());
            ipv6.setNeutronSubnetId(ip.getSubnetId());
            ipv6.setL3InterfaceIpv6PrefixLength(Long.parseLong(cidr.getNetworkPrefixLength().toString()));
            transaction.createIfNotExists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).l3InterfaceIpv6AddressList(ipAddress)), Optional.of(ipv6));
        }
    }
}
Also used : IP(org.openstack4j.model.network.IP) L3InterfaceIpv4AddressList(org.onap.aai.domain.yang.L3InterfaceIpv4AddressList) IPAddressString(inet.ipaddr.IPAddressString) Subnet(org.openstack4j.model.network.Subnet) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) IPAddressString(inet.ipaddr.IPAddressString)

Example 10 with IP

use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.

the class OpenstackDirectPortListCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService service = get(OpenstackNetworkService.class);
    List<Port> ports = service.ports().stream().filter(port -> port.getvNicType().equals(DIRECT)).collect(Collectors.toList());
    print(FORMAT, "ID", "Network", "MAC", "FIXED IPs", "PCI Slot", "Interface");
    for (Port port : ports) {
        List<String> fixedIps = port.getFixedIps().stream().map(IP::getIpAddress).collect(Collectors.toList());
        Network osNet = service.network(port.getNetworkId());
        if (port.getVifType().equals(UNBOUND)) {
            print(FORMAT, port.getId(), deriveResourceName(osNet), port.getMacAddress(), fixedIps.isEmpty() ? "" : fixedIps, UNBOUND, UNBOUND);
        } else {
            print(FORMAT, port.getId(), deriveResourceName(osNet), port.getMacAddress(), fixedIps.isEmpty() ? "" : fixedIps, port.getProfile().containsKey(PCISLOT) ? port.getProfile().get(PCISLOT).toString() : "", getIntfNameFromPciAddress(port));
        }
    }
}
Also used : Network(org.openstack4j.model.network.Network) OpenstackNetworkingUtil.getIntfNameFromPciAddress(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress) PCISLOT(org.onosproject.openstacknetworking.api.Constants.PCISLOT) Collectors(java.util.stream.Collectors) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) List(java.util.List) DIRECT(org.onosproject.openstacknetworking.api.Constants.DIRECT) Service(org.apache.karaf.shell.api.action.lifecycle.Service) IP(org.openstack4j.model.network.IP) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Port(org.openstack4j.model.network.Port) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Port(org.openstack4j.model.network.Port) Network(org.openstack4j.model.network.Network)

Aggregations

IP (org.openstack4j.model.network.IP)12 Port (org.openstack4j.model.network.Port)11 Network (org.openstack4j.model.network.Network)6 Subnet (org.openstack4j.model.network.Subnet)6 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 OpenstackNetworkService (org.onosproject.openstacknetworking.api.OpenstackNetworkService)5 List (java.util.List)4 Objects (java.util.Objects)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Sets (com.google.common.collect.Sets)3 ByteBuffer (java.nio.ByteBuffer)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 Set (java.util.Set)3 L3InterfaceIpv6AddressList (org.onap.aai.domain.yang.L3InterfaceIpv6AddressList)3 ARP (org.onlab.packet.ARP)3 Ethernet (org.onlab.packet.Ethernet)3 IpAddress (org.onlab.packet.IpAddress)3 MacAddress (org.onlab.packet.MacAddress)3 OpenstackNetworkingUtil.deriveResourceName (org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName)3