Search in sources :

Example 16 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackManagementWebResource method syncStates.

/**
 * Synchronizes the network states with openstack.
 *
 * @return 200 OK with sync result, 404 not found
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sync/states")
public Response syncStates() {
    Map<String, String> headerMap = new HashMap();
    headerMap.put(HTTP_HEADER_ACCEPT, HTTP_HEADER_VALUE_JSON);
    Optional<OpenstackNode> node = osNodeAdminService.nodes(CONTROLLER).stream().findFirst();
    if (!node.isPresent()) {
        log.error(AUTH_INFO_NOT_FOUND);
        throw new ItemNotFoundException(AUTH_INFO_NOT_FOUND);
    }
    OSClient osClient = OpenstackNetworkingUtil.getConnectedClient(node.get());
    if (osClient == null) {
        log.error(AUTH_INFO_NOT_CORRECT);
        throw new ItemNotFoundException(AUTH_INFO_NOT_CORRECT);
    }
    try {
        osClient.headers(headerMap).networking().securitygroup().list().forEach(osSg -> {
            if (osSgAdminService.securityGroup(osSg.getId()) != null) {
                osSgAdminService.updateSecurityGroup(osSg);
            } else {
                osSgAdminService.createSecurityGroup(osSg);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve security group due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().network().list().forEach(osNet -> {
            if (osNetAdminService.network(osNet.getId()) != null) {
                osNetAdminService.updateNetwork(osNet);
            } else {
                osNetAdminService.createNetwork(osNet);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve network due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().subnet().list().forEach(osSubnet -> {
            if (osNetAdminService.subnet(osSubnet.getId()) != null) {
                osNetAdminService.updateSubnet(osSubnet);
            } else {
                osNetAdminService.createSubnet(osSubnet);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve subnet due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().port().list().forEach(osPort -> {
            if (osNetAdminService.port(osPort.getId()) != null) {
                osNetAdminService.updatePort(osPort);
            } else {
                osNetAdminService.createPort(osPort);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve port due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().router().list().forEach(osRouter -> {
            if (osRouterAdminService.router(osRouter.getId()) != null) {
                osRouterAdminService.updateRouter(osRouter);
            } else {
                osRouterAdminService.createRouter(osRouter);
            }
            osNetAdminService.ports().stream().filter(osPort -> Objects.equals(osPort.getDeviceId(), osRouter.getId()) && Objects.equals(osPort.getDeviceOwner(), DEVICE_OWNER_IFACE)).forEach(osPort -> addRouterIface(osPort, osRouterAdminService));
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve router due to {}", e.getMessage());
        return Response.serverError().build();
    }
    try {
        osClient.headers(headerMap).networking().floatingip().list().forEach(osFloating -> {
            if (osRouterAdminService.floatingIp(osFloating.getId()) != null) {
                osRouterAdminService.updateFloatingIp(osFloating);
            } else {
                osRouterAdminService.createFloatingIp(osFloating);
            }
        });
    } catch (Exception e) {
        log.warn("Failed to retrieve floating IP due to {}", e.getMessage());
        return Response.serverError().build();
    }
    return ok(mapper().createObjectNode()).build();
}
Also used : AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) OpenstackRoutingArpHandler(org.onosproject.openstacknetworking.impl.OpenstackRoutingArpHandler) OSClient(org.openstack4j.api.OSClient) OpenstackNetworkingUtil(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil) CoreService(org.onosproject.core.CoreService) OpenstackRouterAdminService(org.onosproject.openstacknetworking.api.OpenstackRouterAdminService) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackHaService(org.onosproject.openstacknetworking.api.OpenstackHaService) COMPLETE(org.onosproject.openstacknode.api.NodeState.COMPLETE) OpenstackNetworkingUtil.checkArpMode(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.checkArpMode) OpenstackSecurityGroupAdminService(org.onosproject.openstacknetworking.api.OpenstackSecurityGroupAdminService) MediaType(javax.ws.rs.core.MediaType) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Consumes(javax.ws.rs.Consumes) OpenstackNetworkingUtil.addRouterIface(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.addRouterIface) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) Thread.sleep(java.lang.Thread.sleep) Response.status(javax.ws.rs.core.Response.status) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) ItemNotFoundException(org.onlab.util.ItemNotFoundException) OpenstackNetworkingUtil.getPropertyValueAsBoolean(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValueAsBoolean) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Objects(java.util.Objects) List(java.util.List) NetFloatingIP(org.openstack4j.model.network.NetFloatingIP) Response(javax.ws.rs.core.Response) StreamSupport.stream(java.util.stream.StreamSupport.stream) Optional(java.util.Optional) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) PathParam(javax.ws.rs.PathParam) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) GET(javax.ws.rs.GET) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OpenstackSwitchingArpHandler(org.onosproject.openstacknetworking.impl.OpenstackSwitchingArpHandler) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) OpenstackNetworkingUtil.checkActivationFlag(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.checkActivationFlag) Logger(org.slf4j.Logger) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) OpenstackSecurityGroupHandler(org.onosproject.openstacknetworking.impl.OpenstackSecurityGroupHandler) PUT(javax.ws.rs.PUT) OpenstackRoutingSnatHandler(org.onosproject.openstacknetworking.impl.OpenstackRoutingSnatHandler) Comparator(java.util.Comparator) NodeState(org.onosproject.openstacknode.api.NodeState) HashMap(java.util.HashMap) OSClient(org.openstack4j.api.OSClient) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) ItemNotFoundException(org.onlab.util.ItemNotFoundException) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 17 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackPortWebResource method updatePort.

/**
 * Updates the port with the specified identifier.
 *
 * @param id    port identifier
 * @param input port JSON input stream
 * @return 200 OK with the updated port, 400 BAD_REQUEST if the requested
 * port does not exist
 * @throws IOException exception
 * @onos.rsModel NeutronPort
 */
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updatePort(@PathParam("id") String id, InputStream input) throws IOException {
    log.trace(String.format(MESSAGE, "UPDATE " + id));
    String inputStr = IOUtils.toString(input, REST_UTF8);
    if (!haService.isActive() && !DEFAULT_ACTIVE_IP_ADDRESS.equals(haService.getActiveIp())) {
        return syncPut(haService, PORTS, id, inputStr);
    }
    final NeutronPort port = (NeutronPort) jsonToModelEntity(inputStr, NeutronPort.class);
    adminService.updatePort(port);
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode jsonNode = mapper.createObjectNode();
    OpenstackNode node = nodeService.node(port.getHostId());
    if (node == null) {
        return status(Response.Status.OK).build();
    } else if (node.datapathType().equals(DpdkConfig.DatapathType.NETDEV)) {
        log.debug("UpdatePort for port {} called in netdev device {} " + "so sends vif type as a payload of the response", port.getId(), node.hostname());
        jsonNode.put(VIF_TYPE, VHOSTUSER);
        if (node.socketDir() != null) {
            jsonNode.put(SOCKET_DIR, node.socketDir());
        }
        return status(Response.Status.OK).entity(jsonNode.toString()).build();
    } else {
        return status(Response.Status.OK).build();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NeutronPort(org.openstack4j.openstack.networking.domain.NeutronPort) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 18 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackNetworkingUtilTest method testGetGwByComputeDevId.

/**
 * Tests the getGwByComputeDevId method.
 */
@Test
public void testGetGwByComputeDevId() {
    Set<OpenstackNode> gws = Sets.newConcurrentHashSet();
    OpenstackNode nullGw = getGwByComputeDevId(gws, genDeviceId(1));
    assertNull(nullGw);
    gws.add(genGateway(1));
    gws.add(genGateway(2));
    gws.add(genGateway(3));
    Set<OpenstackNode> cloneOfGws = ImmutableSet.copyOf(gws);
    Map<String, Integer> gwCountMap = Maps.newConcurrentMap();
    int numOfDev = 99;
    for (int i = 1; i < 1 + numOfDev; i++) {
        OpenstackNode gw = getGwByComputeDevId(gws, genDeviceId(i));
        if (gwCountMap.get(gw.hostname()) == null) {
            gwCountMap.put(gw.hostname(), 1);
        } else {
            gwCountMap.compute(gw.hostname(), (k, v) -> v + 1);
        }
        new EqualsTester().addEqualityGroup(getGwByComputeDevId(gws, genDeviceId(i)), getGwByComputeDevId(cloneOfGws, genDeviceId(i))).testEquals();
    }
    int sum = gwCountMap.values().stream().mapToInt(Integer::intValue).sum();
    assertEquals(numOfDev, sum);
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) DefaultOpenstackNode(org.onosproject.openstacknode.api.DefaultOpenstackNode) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) OpenstackNodeTest(org.onosproject.openstacknode.api.OpenstackNodeTest) Test(org.junit.Test) OpenstackFloatingIpWebResourceTest(org.onosproject.openstacknetworking.web.OpenstackFloatingIpWebResourceTest) OpenstackNetworkWebResourceTest(org.onosproject.openstacknetworking.web.OpenstackNetworkWebResourceTest)

Example 19 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackNodeCheckCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    DeviceService deviceService = get(DeviceService.class);
    OpenstackNode osNode = osNodeService.node(hostname);
    if (osNode == null) {
        print("Cannot find %s from registered nodes", hostname);
        return;
    }
    if (osNode.type() == CONTROLLER) {
        print("[Openstack Controller Status]");
        OSClient client = getConnectedClient(osNode);
        if (client == null) {
            error("The given keystone info is incorrect to get authorized to openstack");
            print("keystoneConfig=%s", osNode.keystoneConfig());
        }
        if (osNode.keystoneConfig() != null) {
            print("%s keystoneConfig=%s, neutronConfig=%s", osNode.state() == NodeState.COMPLETE && client != null ? MSG_OK : MSG_ERROR, osNode.keystoneConfig(), osNode.neutronConfig());
        } else {
            print("%s keystoneConfig is missing", MSG_ERROR);
        }
    } else {
        print("[Integration Bridge Status]");
        Device device = deviceService.getDevice(osNode.intgBridge());
        Device ovsdbDevice = deviceService.getDevice(osNode.ovsdb());
        if (device != null) {
            print("%s OvsdbDeviceId=%s available=%s", deviceService.isAvailable(ovsdbDevice.id()) ? MSG_OK : MSG_ERROR, ovsdbDevice.id(), deviceService.isAvailable(ovsdbDevice.id()));
            print("%s %s=%s available=%s %s", deviceService.isAvailable(device.id()) ? MSG_OK : MSG_ERROR, INTEGRATION_BRIDGE, device.id(), deviceService.isAvailable(device.id()), device.annotations());
            if (osNode.dataIp() != null) {
                printPortState(deviceService, osNode.intgBridge(), VXLAN_TUNNEL);
                printPortState(deviceService, osNode.intgBridge(), GRE_TUNNEL);
                printPortState(deviceService, osNode.intgBridge(), GENEVE_TUNNEL);
            }
            if (osNode.vlanIntf() != null) {
                printPortState(deviceService, osNode.intgBridge(), osNode.vlanIntf());
            }
            osNode.phyIntfs().forEach(intf -> {
                printPortState(deviceService, osNode.intgBridge(), structurePortName(INTEGRATION_TO_PHYSICAL_PREFIX + intf.network()));
            });
            if (osNode.type() == GATEWAY) {
                printPortState(deviceService, osNode.intgBridge(), osNode.uplinkPort());
            }
        } else {
            print("%s %s=%s is not available", MSG_ERROR, INTEGRATION_BRIDGE, osNode.intgBridge());
        }
    }
}
Also used : OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OSClient(org.openstack4j.api.OSClient) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 20 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackNodeListCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    List<OpenstackNode> osNodes = Lists.newArrayList(osNodeService.nodes());
    osNodes.sort(Comparator.comparing(OpenstackNode::hostname));
    if (outputJson()) {
        print("%s", json(osNodes));
    } else {
        print(FORMAT, "Hostname", "Type", "Integration Bridge", "Management IP", "Data IP", "VLAN Intf", "Uplink Port", "State", "SelectedGw");
        for (OpenstackNode osNode : osNodes) {
            print(FORMAT, osNode.hostname(), osNode.type(), osNode.intgBridge(), osNode.managementIp(), osNode.dataIp() != null ? osNode.dataIp() : "", osNode.vlanIntf() != null ? osNode.vlanIntf() : "", osNode.uplinkPort() != null ? osNode.uplinkPort() : "", osNode.state(), getGwByComputeNode(osNodeService.completeNodes(GATEWAY), osNode));
        }
        print("Total %s nodes", osNodeService.nodes().size());
    }
}
Also used : OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Aggregations

OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)76 OpenstackNodeService (org.onosproject.openstacknode.api.OpenstackNodeService)22 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)19 PortNumber (org.onosproject.net.PortNumber)14 DefaultOpenstackNode (org.onosproject.openstacknode.api.DefaultOpenstackNode)14 DeviceService (org.onosproject.net.device.DeviceService)13 Set (java.util.Set)12 Test (org.junit.Test)12 IpAddress (org.onlab.packet.IpAddress)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 Objects (java.util.Objects)9 Optional (java.util.Optional)9 ExecutorService (java.util.concurrent.ExecutorService)9 Collectors (java.util.stream.Collectors)9 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)9 Produces (javax.ws.rs.Produces)8 InstancePort (org.onosproject.openstacknetworking.api.InstancePort)7