Search in sources :

Example 1 with ContrailSubnetHostRoutes

use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.

the class ContrailSubnetMappersTest method createContrailSubnetHostRoutesMissingFieldTest.

@Test
public void createContrailSubnetHostRoutesMissingFieldTest() {
    List<HostRoute> hostRoutes = new ArrayList<>();
    HostRoute hostRoute1 = new HostRoute();
    hostRoute1.setNextHop("next-hop1");
    HostRoute hostRoute2 = new HostRoute();
    hostRoute2.setNextHop("next-hop2");
    hostRoute2.setPrefix("prefix2");
    hostRoutes.add(hostRoute1);
    hostRoutes.add(hostRoute2);
    Subnet subnet = new Subnet();
    subnet.setHostRoutes(hostRoutes);
    ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
    ContrailSubnet result = mapper.map();
    ContrailSubnetHostRoutes routes = result.getHostRoutes();
    assertEquals(2, routes.getHostRoutes().size());
    assertEquals("next-hop1", routes.getHostRoutes().get(0).getNextHop());
    assertEquals("prefix2", routes.getHostRoutes().get(1).getPrefix());
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ArrayList(java.util.ArrayList) ContrailSubnetHostRoutes(org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes) HostRoute(org.onap.so.openstack.beans.HostRoute) ContrailSubnetHostRoute(org.onap.so.adapters.network.beans.ContrailSubnetHostRoute) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) Test(org.junit.Test)

Example 2 with ContrailSubnetHostRoutes

use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.

the class ContrailSubnetMappersTest method createContrailSubnetHostRoutesEmptyTest.

@Test
public void createContrailSubnetHostRoutesEmptyTest() {
    List<HostRoute> hostRoutes = new ArrayList<>();
    Subnet subnet = new Subnet();
    subnet.setHostRoutes(hostRoutes);
    ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
    ContrailSubnet result = mapper.map();
    ContrailSubnetHostRoutes routes = result.getHostRoutes();
    assertEquals(true, routes.getHostRoutes().isEmpty());
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ArrayList(java.util.ArrayList) ContrailSubnetHostRoutes(org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes) HostRoute(org.onap.so.openstack.beans.HostRoute) ContrailSubnetHostRoute(org.onap.so.adapters.network.beans.ContrailSubnetHostRoute) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) Test(org.junit.Test)

Example 3 with ContrailSubnetHostRoutes

use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.

the class ContrailSubnetMappersTest method createContrailSubnetHostRoutesTest.

@Test
public void createContrailSubnetHostRoutesTest() {
    List<HostRoute> hostRoutes = new ArrayList<>();
    HostRoute hostRoute1 = new HostRoute();
    hostRoute1.setNextHop("next-hop1");
    hostRoute1.setPrefix("prefix1");
    HostRoute hostRoute2 = new HostRoute();
    hostRoute2.setNextHop("next-hop2");
    hostRoute2.setPrefix("prefix2");
    hostRoutes.add(hostRoute1);
    hostRoutes.add(hostRoute2);
    Subnet subnet = new Subnet();
    subnet.setHostRoutes(hostRoutes);
    ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet);
    ContrailSubnet result = mapper.map();
    ContrailSubnetHostRoutes routes = result.getHostRoutes();
    assertEquals(2, routes.getHostRoutes().size());
    assertEquals("next-hop2", routes.getHostRoutes().get(1).getNextHop());
    assertEquals("prefix2", routes.getHostRoutes().get(1).getPrefix());
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ArrayList(java.util.ArrayList) ContrailSubnetHostRoutes(org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes) HostRoute(org.onap.so.openstack.beans.HostRoute) ContrailSubnetHostRoute(org.onap.so.adapters.network.beans.ContrailSubnetHostRoute) Subnet(org.onap.so.openstack.beans.Subnet) ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) Test(org.junit.Test)

Example 4 with ContrailSubnetHostRoutes

use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.

the class ContrailSubnetMapper method map.

public ContrailSubnet map() {
    final ContrailSubnet result = new ContrailSubnet();
    if (inputSubnet != null) {
        final String subnetname = this.getSubnetName(inputSubnet);
        result.setSubnetName(subnetname);
        result.setEnableDhcp(inputSubnet.getEnableDHCP());
        result.setDefaultGateway(inputSubnet.getGatewayIp());
        Optional<ContrailSubnetIp> csIp = createSubnet(inputSubnet);
        if (csIp.isPresent()) {
            result.setSubnet(csIp.get());
        }
        Optional<List<ContrailSubnetPool>> pools = this.createContrailSubnetPool(inputSubnet);
        if (pools.isPresent()) {
            result.setAllocationPools(pools.get());
        }
        Optional<ContrailSubnetHostRoutes> routes = this.createContrailSubnetHostRoutes(inputSubnet);
        if (routes.isPresent()) {
            result.setHostRoutes(routes.get());
        }
    }
    return result;
}
Also used : ContrailSubnet(org.onap.so.adapters.network.beans.ContrailSubnet) ContrailSubnetIp(org.onap.so.adapters.network.beans.ContrailSubnetIp) ContrailSubnetHostRoutes(org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with ContrailSubnetHostRoutes

use of org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes in project so by onap.

the class ContrailSubnetMapper method createContrailSubnetHostRoutes.

protected Optional<ContrailSubnetHostRoutes> createContrailSubnetHostRoutes(final Subnet subnet) {
    Optional<ContrailSubnetHostRoutes> result = Optional.empty();
    if (subnet.getHostRoutes() != null) {
        ContrailSubnetHostRoutes hostRoutesObj = new ContrailSubnetHostRoutes();
        List<ContrailSubnetHostRoute> hrList = new ArrayList<>();
        for (HostRoute hr : subnet.getHostRoutes()) {
            if (!isNullOrEmpty(hr.getPrefix()) || !isNullOrEmpty(hr.getNextHop())) {
                hrList.add(new ContrailSubnetHostRouteMapper(hr).map());
            }
        }
        if (!hrList.isEmpty()) {
            hostRoutesObj.setHostRoutes(hrList);
            result = Optional.of(hostRoutesObj);
        }
    }
    return result;
}
Also used : ContrailSubnetHostRoutes(org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes) ArrayList(java.util.ArrayList) ContrailSubnetHostRoute(org.onap.so.adapters.network.beans.ContrailSubnetHostRoute) HostRoute(org.onap.so.openstack.beans.HostRoute) ContrailSubnetHostRoute(org.onap.so.adapters.network.beans.ContrailSubnetHostRoute)

Aggregations

ArrayList (java.util.ArrayList)5 ContrailSubnetHostRoutes (org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes)5 ContrailSubnet (org.onap.so.adapters.network.beans.ContrailSubnet)4 ContrailSubnetHostRoute (org.onap.so.adapters.network.beans.ContrailSubnetHostRoute)4 HostRoute (org.onap.so.openstack.beans.HostRoute)4 Test (org.junit.Test)3 Subnet (org.onap.so.openstack.beans.Subnet)3 List (java.util.List)1 ContrailSubnetIp (org.onap.so.adapters.network.beans.ContrailSubnetIp)1