Search in sources :

Example 36 with ControllerInfo

use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.

the class OpenstackNodeCodec method decode.

@Override
public OpenstackNode decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    String hostname = nullIsIllegal(json.get(HOST_NAME).asText(), HOST_NAME + MISSING_MESSAGE);
    String type = nullIsIllegal(json.get(TYPE).asText(), TYPE + MISSING_MESSAGE);
    String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(), MANAGEMENT_IP + MISSING_MESSAGE);
    DefaultOpenstackNode.Builder nodeBuilder = DefaultOpenstackNode.builder().hostname(hostname).type(OpenstackNode.NodeType.valueOf(type)).state(NodeState.INIT).managementIp(IpAddress.valueOf(mIp));
    if (type.equals(GATEWAY)) {
        nodeBuilder.uplinkPort(nullIsIllegal(json.get(UPLINK_PORT).asText(), UPLINK_PORT + MISSING_MESSAGE));
    }
    if (type.equals(CONTROLLER)) {
        JsonNode keystoneConfigJson = json.get(KEYSTONE_CONFIG);
        KeystoneConfig keystoneConfig;
        if (keystoneConfigJson != null) {
            final JsonCodec<KeystoneConfig> keystoneConfigCodec = context.codec(KeystoneConfig.class);
            keystoneConfig = keystoneConfigCodec.decode((ObjectNode) keystoneConfigJson.deepCopy(), context);
        } else {
            JsonNode authJson = json.get(AUTHENTICATION);
            final JsonCodec<OpenstackAuth> authCodec = context.codec(OpenstackAuth.class);
            OpenstackAuth auth = authCodec.decode((ObjectNode) authJson.deepCopy(), context);
            String endpoint = nullIsIllegal(json.get(ENDPOINT).asText(), ENDPOINT + MISSING_MESSAGE);
            keystoneConfig = DefaultKeystoneConfig.builder().authentication(auth).endpoint(endpoint).build();
        }
        nodeBuilder.keystoneConfig(keystoneConfig);
    }
    if (json.get(VLAN_INTF_NAME) != null) {
        nodeBuilder.vlanIntf(json.get(VLAN_INTF_NAME).asText());
    }
    if (json.get(DATA_IP) != null) {
        nodeBuilder.dataIp(IpAddress.valueOf(json.get(DATA_IP).asText()));
    }
    JsonNode intBridgeJson = json.get(INTEGRATION_BRIDGE);
    if (intBridgeJson != null) {
        nodeBuilder.intgBridge(DeviceId.deviceId(intBridgeJson.asText()));
    }
    // parse physical interfaces
    List<OpenstackPhyInterface> phyIntfs = new ArrayList<>();
    JsonNode phyIntfsJson = json.get(PHYSICAL_INTERFACES);
    if (phyIntfsJson != null) {
        final JsonCodec<OpenstackPhyInterface> phyIntfCodec = context.codec(OpenstackPhyInterface.class);
        IntStream.range(0, phyIntfsJson.size()).forEach(i -> {
            ObjectNode intfJson = get(phyIntfsJson, i);
            phyIntfs.add(phyIntfCodec.decode(intfJson, context));
        });
    }
    nodeBuilder.phyIntfs(phyIntfs);
    // parse customized controllers
    List<ControllerInfo> controllers = new ArrayList<>();
    JsonNode controllersJson = json.get(CONTROLLERS);
    if (controllersJson != null) {
        final JsonCodec<ControllerInfo> controllerCodec = context.codec(ControllerInfo.class);
        IntStream.range(0, controllersJson.size()).forEach(i -> {
            ObjectNode controllerJson = get(controllersJson, i);
            controllers.add(controllerCodec.decode(controllerJson, context));
        });
    }
    nodeBuilder.controllers(controllers);
    // parse neutron config
    JsonNode neutronConfigJson = json.get(NEUTRON_CONFIG);
    if (neutronConfigJson != null) {
        final JsonCodec<NeutronConfig> neutronConfigJsonCodec = context.codec(NeutronConfig.class);
        NeutronConfig neutronConfig = neutronConfigJsonCodec.decode((ObjectNode) neutronConfigJson.deepCopy(), context);
        nodeBuilder.neutronConfig(neutronConfig);
    }
    // parse ssh authentication
    JsonNode sshAuthJson = json.get(SSH_AUTH);
    if (sshAuthJson != null) {
        final JsonCodec<OpenstackSshAuth> sshAuthJsonCodec = context.codec(OpenstackSshAuth.class);
        OpenstackSshAuth sshAuth = sshAuthJsonCodec.decode((ObjectNode) sshAuthJson.deepCopy(), context);
        nodeBuilder.sshAuthInfo(sshAuth);
    }
    // parse DPDK configuration
    JsonNode dpdkConfigJson = json.get(DPDK_CONFIG);
    if (dpdkConfigJson != null) {
        final JsonCodec<DpdkConfig> dpdkConfigJsonCodec = context.codec(DpdkConfig.class);
        DpdkConfig dpdkConfig = dpdkConfigJsonCodec.decode((ObjectNode) dpdkConfigJson.deepCopy(), context);
        nodeBuilder.dpdkConfig(dpdkConfig);
    }
    log.trace("node is {}", nodeBuilder.build().toString());
    return nodeBuilder.build();
}
Also used : OpenstackAuth(org.onosproject.openstacknode.api.OpenstackAuth) NeutronConfig(org.onosproject.openstacknode.api.NeutronConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KeystoneConfig(org.onosproject.openstacknode.api.KeystoneConfig) DefaultKeystoneConfig(org.onosproject.openstacknode.api.DefaultKeystoneConfig) DefaultOpenstackNode(org.onosproject.openstacknode.api.DefaultOpenstackNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) DpdkConfig(org.onosproject.openstacknode.api.DpdkConfig) OpenstackSshAuth(org.onosproject.openstacknode.api.OpenstackSshAuth) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 37 with ControllerInfo

use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.

the class DefaultOpenstackNodeHandler method createBridge.

/**
 * Creates a bridge with a given name on a given openstack node.
 *
 * @param osNode openstack node
 * @param bridgeName bridge name
 * @param deviceId device identifier
 */
private void createBridge(OpenstackNode osNode, String bridgeName, DeviceId deviceId) {
    Device device = deviceService.getDevice(osNode.ovsdb());
    List<ControllerInfo> controllers;
    if (osNode.controllers() != null && osNode.controllers().size() > 0) {
        controllers = (List<ControllerInfo>) osNode.controllers();
    } else {
        Set<IpAddress> controllerIps = clusterService.getNodes().stream().map(ControllerNode::ip).collect(Collectors.toSet());
        controllers = controllerIps.stream().map(ip -> new ControllerInfo(ip, DEFAULT_OFPORT, DEFAULT_OF_PROTO)).collect(Collectors.toList());
    }
    String dpid = deviceId.toString().substring(DPID_BEGIN);
    BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(bridgeName).failMode(BridgeDescription.FailMode.SECURE).datapathId(dpid).disableInBand().mcastSnoopingEnable().controllers(controllers);
    if (osNode.datapathType().equals(NETDEV)) {
        builder.datapathType(NETDEV.name().toLowerCase());
    }
    BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
    bridgeConfig.addBridge(builder.build());
}
Also used : Device(org.onosproject.net.Device) IpAddress(org.onlab.packet.IpAddress) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 38 with ControllerInfo

use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.

the class DefaultK8sNodeHandler method createBridge.

/**
 * Creates a bridge with a given name on a given kubernetes node.
 *
 * @param k8sNode       kubernetes node
 * @param bridgeName    bridge name
 * @param devId         device identifier
 */
private void createBridge(K8sNode k8sNode, String bridgeName, DeviceId devId) {
    Device device = deviceService.getDevice(k8sNode.ovsdb());
    List<ControllerInfo> controllers = k8sApiConfigService.apiConfigs().stream().map(c -> new ControllerInfo(c.ipAddress(), DEFAULT_OFPORT, DEFAULT_OF_PROTO)).collect(Collectors.toList());
    String dpid = devId.toString().substring(DPID_BEGIN);
    BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(bridgeName).failMode(BridgeDescription.FailMode.SECURE).datapathId(dpid).disableInBand().controllers(controllers);
    BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
    bridgeConfig.addBridge(builder.build());
}
Also used : DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) K8sApiConfigService(org.onosproject.k8snode.api.K8sApiConfigService) CoreService(org.onosproject.core.CoreService) K8sNodeAdminService(org.onosproject.k8snode.api.K8sNodeAdminService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) K8sNodeListener(org.onosproject.k8snode.api.K8sNodeListener) VXLAN(org.onosproject.k8snode.api.Constants.VXLAN) TpPort.tpPort(org.onlab.packet.TpPort.tpPort) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) Thread.sleep(java.lang.Thread.sleep) K8sNodeState(org.onosproject.k8snode.api.K8sNodeState) NodeId(org.onosproject.cluster.NodeId) INCOMPLETE(org.onosproject.k8snode.api.K8sNodeState.INCOMPLETE) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) AUTO_RECOVERY(org.onosproject.k8snode.impl.OsgiPropertyConstants.AUTO_RECOVERY) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) K8sNodeUtil.getBooleanProperty(org.onosproject.k8snode.util.K8sNodeUtil.getBooleanProperty) K8sNodeUtil.isOvsdbConnected(org.onosproject.k8snode.util.K8sNodeUtil.isOvsdbConnected) DefaultPatchDescription(org.onosproject.net.behaviour.DefaultPatchDescription) Objects(java.util.Objects) List(java.util.List) TunnelEndPoints(org.onosproject.net.behaviour.TunnelEndPoints) DeviceEvent(org.onosproject.net.device.DeviceEvent) AUTO_RECOVERY_DEFAULT(org.onosproject.k8snode.impl.OsgiPropertyConstants.AUTO_RECOVERY_DEFAULT) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) InterfaceConfig(org.onosproject.net.behaviour.InterfaceConfig) GENEVE(org.onosproject.k8snode.api.Constants.GENEVE) GRE(org.onosproject.k8snode.api.Constants.GRE) Tools(org.onlab.util.Tools) K8sNodeUtil.getOvsdbClient(org.onosproject.k8snode.util.K8sNodeUtil.getOvsdbClient) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) ComponentContext(org.osgi.service.component.ComponentContext) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) TunnelKey(org.onosproject.net.behaviour.TunnelKey) Component(org.osgi.service.component.annotations.Component) DefaultTunnelDescription(org.onosproject.net.behaviour.DefaultTunnelDescription) DEVICE_CREATED(org.onosproject.k8snode.api.K8sNodeState.DEVICE_CREATED) K8sNodeEvent(org.onosproject.k8snode.api.K8sNodeEvent) Activate(org.osgi.service.component.annotations.Activate) COMPLETE(org.onosproject.k8snode.api.K8sNodeState.COMPLETE) K8sNode(org.onosproject.k8snode.api.K8sNode) ExecutorService(java.util.concurrent.ExecutorService) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) K8sNodeHandler(org.onosproject.k8snode.api.K8sNodeHandler) PatchDescription(org.onosproject.net.behaviour.PatchDescription) APP_ID(org.onosproject.k8snode.api.K8sNodeService.APP_ID) TunnelDescription(org.onosproject.net.behaviour.TunnelDescription) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) OVSDB_PORT(org.onosproject.k8snode.impl.OsgiPropertyConstants.OVSDB_PORT) Modified(org.osgi.service.component.annotations.Modified) OVSDB_PORT_NUM_DEFAULT(org.onosproject.k8snode.impl.OsgiPropertyConstants.OVSDB_PORT_NUM_DEFAULT) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) NORMAL(org.onosproject.k8snode.api.K8sApiConfig.Mode.NORMAL) Device(org.onosproject.net.Device) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Aggregations

ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)38 ArrayList (java.util.ArrayList)19 DeviceId (org.onosproject.net.DeviceId)11 IpAddress (org.onlab.packet.IpAddress)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 Test (org.junit.Test)7 Device (org.onosproject.net.Device)6 BridgeConfig (org.onosproject.net.behaviour.BridgeConfig)6 BridgeDescription (org.onosproject.net.behaviour.BridgeDescription)6 DefaultBridgeDescription (org.onosproject.net.behaviour.DefaultBridgeDescription)6 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)5 Objects (java.util.Objects)5 Collectors (java.util.stream.Collectors)5 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)5 DriverHandler (org.onosproject.net.driver.DriverHandler)5 Logger (org.slf4j.Logger)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4