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();
}
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());
}
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());
}
Aggregations