Search in sources :

Example 1 with ControllerInfo

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

the class DefaultK8sHostHandler method createBridge.

private void createBridge(DeviceId ovsdb, K8sBridge bridge) {
    Device device = deviceService.getDevice(ovsdb);
    List<ControllerInfo> controllers = clusterService.getNodes().stream().map(n -> new ControllerInfo(n.ip(), DEFAULT_OFPORT, DEFAULT_OF_PROTO)).collect(Collectors.toList());
    String dpid = bridge.dpid().substring(DPID_BEGIN);
    BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(bridge.name()).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) CoreService(org.onosproject.core.CoreService) K8sNodeAdminService(org.onosproject.k8snode.api.K8sNodeAdminService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) K8sHostState(org.onosproject.k8snode.api.K8sHostState) VXLAN(org.onosproject.k8snode.api.Constants.VXLAN) TpPort.tpPort(org.onlab.packet.TpPort.tpPort) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) K8sHostListener(org.onosproject.k8snode.api.K8sHostListener) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) Thread.sleep(java.lang.Thread.sleep) NodeId(org.onosproject.cluster.NodeId) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) DefaultPatchDescription(org.onosproject.net.behaviour.DefaultPatchDescription) Objects(java.util.Objects) DEVICE_CREATED(org.onosproject.k8snode.api.K8sHostState.DEVICE_CREATED) List(java.util.List) COMPLETE(org.onosproject.k8snode.api.K8sHostState.COMPLETE) TunnelEndPoints(org.onosproject.net.behaviour.TunnelEndPoints) K8sTunnelBridge(org.onosproject.k8snode.api.K8sTunnelBridge) K8sHostEvent(org.onosproject.k8snode.api.K8sHostEvent) DeviceEvent(org.onosproject.net.device.DeviceEvent) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) 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) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) TunnelKey(org.onosproject.net.behaviour.TunnelKey) INIT(org.onosproject.k8snode.api.K8sHostState.INIT) K8sRouterBridge(org.onosproject.k8snode.api.K8sRouterBridge) Component(org.osgi.service.component.annotations.Component) DefaultTunnelDescription(org.onosproject.net.behaviour.DefaultTunnelDescription) Activate(org.osgi.service.component.annotations.Activate) K8sNode(org.onosproject.k8snode.api.K8sNode) ExecutorService(java.util.concurrent.ExecutorService) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DeviceListener(org.onosproject.net.device.DeviceListener) OS_INTEGRATION_BRIDGE(org.onosproject.k8snode.api.Constants.OS_INTEGRATION_BRIDGE) Logger(org.slf4j.Logger) PatchDescription(org.onosproject.net.behaviour.PatchDescription) APP_ID(org.onosproject.k8snode.api.K8sNodeService.APP_ID) TunnelDescription(org.onosproject.net.behaviour.TunnelDescription) K8sHostHandler(org.onosproject.k8snode.api.K8sHostHandler) K8sBridge(org.onosproject.k8snode.api.K8sBridge) K8sHostAdminService(org.onosproject.k8snode.api.K8sHostAdminService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) INCOMPLETE(org.onosproject.k8snode.api.K8sHostState.INCOMPLETE) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) K8sHost(org.onosproject.k8snode.api.K8sHost) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) 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)

Example 2 with ControllerInfo

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

the class KubevirtNetworkHandler method createBridge.

private void createBridge(KubevirtNode node, KubevirtNetwork network) {
    Device tenantBridge = deviceService.getDevice(network.tenantDeviceId(node.hostname()));
    if (tenantBridge != null && deviceService.isAvailable(tenantBridge.id())) {
        log.warn("The tenant bridge {} already exists at node {}", network.tenantBridgeName(), node.hostname());
        return;
    }
    Device device = deviceService.getDevice(node.ovsdb());
    IpAddress controllerIp = apiConfigService.apiConfig().controllerIp();
    String serviceFqdn = apiConfigService.apiConfig().serviceFqdn();
    IpAddress serviceIp = null;
    if (controllerIp == null) {
        if (serviceFqdn != null) {
            serviceIp = resolveHostname(serviceFqdn);
        }
        if (serviceIp != null) {
            controllerIp = serviceIp;
        } else {
            controllerIp = apiConfigService.apiConfig().ipAddress();
        }
    }
    ControllerInfo controlInfo = new ControllerInfo(controllerIp, DEFAULT_OFPORT, DEFAULT_OF_PROTO);
    List<ControllerInfo> controllers = Lists.newArrayList(controlInfo);
    String dpid = network.tenantDeviceId(node.hostname()).toString().substring(DPID_BEGIN);
    // if the bridge is already available, we skip creating a new bridge
    if (!deviceService.isAvailable(DeviceId.deviceId(dpid))) {
        BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(network.tenantBridgeName()).failMode(BridgeDescription.FailMode.SECURE).datapathId(dpid).disableInBand().controllers(controllers);
        BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
        bridgeConfig.addBridge(builder.build());
        log.info("Created a new tunnel bridge for network {} at node {}", network.networkId(), node.hostname());
        waitFor(3);
    }
}
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 3 with ControllerInfo

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

the class DefaultKubevirtNodeHandler method createBridge.

/**
 * Creates a bridge with a given name on a given kubernetes node.
 *
 * @param node          kubevirt node
 * @param bridgeName    bridge name
 * @param devId         device identifier
 */
private void createBridge(KubevirtNode node, String bridgeName, DeviceId devId) {
    Device device = deviceService.getDevice(node.ovsdb());
    IpAddress controllerIp = apiConfigService.apiConfig().controllerIp();
    String serviceFqdn = apiConfigService.apiConfig().serviceFqdn();
    IpAddress serviceIp = null;
    if (controllerIp == null) {
        if (serviceFqdn != null) {
            serviceIp = resolveHostname(serviceFqdn);
        }
        if (serviceIp != null) {
            controllerIp = serviceIp;
        } else {
            controllerIp = apiConfigService.apiConfig().ipAddress();
        }
    }
    ControllerInfo controlInfo = new ControllerInfo(controllerIp, DEFAULT_OFPORT, DEFAULT_OF_PROTO);
    List<ControllerInfo> controllers = Lists.newArrayList(controlInfo);
    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 : 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 4 with ControllerInfo

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

the class OpenstackNodeCodecTest method testOpenstackComputeNodeEncode.

/**
 * Tests the openstack compute node encoding.
 */
@Test
public void testOpenstackComputeNodeEncode() {
    OpenstackPhyInterface phyIntf1 = DefaultOpenstackPhyInterface.builder().network("mgmtnetwork").intf("eth3").build();
    OpenstackPhyInterface phyIntf2 = DefaultOpenstackPhyInterface.builder().network("oamnetwork").intf("eth4").build();
    OpenstackSshAuth sshAuth = DefaultOpenstackSshAuth.builder().id("sdn").password("sdn").build();
    ControllerInfo controller1 = new ControllerInfo(IpAddress.valueOf("10.10.10.2"), 6653, "tcp");
    ControllerInfo controller2 = new ControllerInfo(IpAddress.valueOf("10.10.10.3"), 6663, "tcp");
    OpenstackNode node = DefaultOpenstackNode.builder().hostname("compute").type(OpenstackNode.NodeType.COMPUTE).state(NodeState.INIT).managementIp(IpAddress.valueOf("10.10.10.1")).intgBridge(DeviceId.deviceId("br-int")).vlanIntf("vlan").dataIp(IpAddress.valueOf("20.20.20.2")).phyIntfs(ImmutableList.of(phyIntf1, phyIntf2)).controllers(ImmutableList.of(controller1, controller2)).sshAuthInfo(sshAuth).build();
    ObjectNode nodeJson = openstackNodeCodec.encode(node, context);
    assertThat(nodeJson, matchesOpenstackNode(node));
}
Also used : OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) DefaultOpenstackPhyInterface(org.onosproject.openstacknode.api.DefaultOpenstackPhyInterface) DefaultOpenstackSshAuth(org.onosproject.openstacknode.api.DefaultOpenstackSshAuth) OpenstackSshAuth(org.onosproject.openstacknode.api.OpenstackSshAuth) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OpenstackNodeJsonMatcher.matchesOpenstackNode(org.onosproject.openstacknode.codec.OpenstackNodeJsonMatcher.matchesOpenstackNode) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultOpenstackNode(org.onosproject.openstacknode.api.DefaultOpenstackNode) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Test(org.junit.Test)

Example 5 with ControllerInfo

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

the class DeviceSetControllersCommand method doExecute.

@Override
protected void doExecute() {
    if (controllersListStrings == null && !removeCont && !removeAll) {
        print("No controller are given, skipping.");
        return;
    }
    if (controllersListStrings != null) {
        Arrays.asList(controllersListStrings).forEach(cInfoString -> {
            ControllerInfo controllerInfo = parseCInfoString(cInfoString);
            if (controllerInfo != null) {
                controllers.add(controllerInfo);
            }
        });
    }
    DriverService service = get(DriverService.class);
    deviceId = DeviceId.deviceId(uri);
    DriverHandler h = service.createHandler(deviceId);
    ControllerConfig config = h.behaviour(ControllerConfig.class);
    print("before:");
    config.getControllers().forEach(c -> print(c.target()));
    try {
        if (removeAll) {
            if (!controllers.isEmpty()) {
                print("Controllers list should be empty to remove all controllers");
            } else {
                List<ControllerInfo> controllersToRemove = config.getControllers();
                controllersToRemove.forEach(c -> print("Will remove " + c.target()));
                config.removeControllers(controllersToRemove);
            }
        } else {
            if (controllers.isEmpty()) {
                print("Controllers list is empty, cannot set/remove empty controllers");
            } else {
                if (removeCont) {
                    print("Will remove specified controllers");
                    config.removeControllers(controllers);
                } else {
                    print("Will add specified controllers");
                    config.setControllers(controllers);
                }
            }
        }
    } catch (NullPointerException e) {
        print("No Device with requested parameters {} ", uri);
    }
    print("after:");
    config.getControllers().forEach(c -> print(c.target()));
    print("size %d", config.getControllers().size());
}
Also used : ControllerConfig(org.onosproject.net.behaviour.ControllerConfig) DriverHandler(org.onosproject.net.driver.DriverHandler) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DriverService(org.onosproject.net.driver.DriverService)

Aggregations

ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)37 ArrayList (java.util.ArrayList)19 DeviceId (org.onosproject.net.DeviceId)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 IpAddress (org.onlab.packet.IpAddress)8 Test (org.junit.Test)7 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 Device (org.onosproject.net.Device)5 BridgeConfig (org.onosproject.net.behaviour.BridgeConfig)5 BridgeDescription (org.onosproject.net.behaviour.BridgeDescription)5 DefaultBridgeDescription (org.onosproject.net.behaviour.DefaultBridgeDescription)5 DriverHandler (org.onosproject.net.driver.DriverHandler)5 Logger (org.slf4j.Logger)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4