use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class RestSBControllerMock method get.
@Override
public InputStream get(DeviceId device, String request, MediaType mediaType) {
/**
* We fake the HTTP get in order to
* emulate the expected response.
*/
ObjectMapper mapper = new ObjectMapper();
// Create the object node to host the data
ObjectNode sendObjNode = mapper.createObjectNode();
// Insert header
ArrayNode ctrlsArrayNode = sendObjNode.putArray(PARAM_CTRL);
// Add each controller's information object
for (ControllerInfo ctrl : controllers) {
ObjectNode ctrlObjNode = mapper.createObjectNode();
ctrlObjNode.put(PARAM_CTRL_IP, ctrl.ip().toString());
ctrlObjNode.put(PARAM_CTRL_PORT, ctrl.port());
ctrlObjNode.put(PARAM_CTRL_TYPE, ctrl.type());
ctrlsArrayNode.add(ctrlObjNode);
}
return new ByteArrayInputStream(sendObjNode.toString().getBytes());
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class DeviceSetControllersCommand method getControllerInfo.
private ControllerInfo getControllerInfo(Annotations annotation, String s) {
String[] data = s.split(":");
if (data.length != 3) {
print("Wrong format of the controller %s, should be in the format <protocol>:<ip>:<port>", s);
return null;
}
String type = data[0];
IpAddress ip = IpAddress.valueOf(data[1]);
int port = Integer.parseInt(data[2]);
if (annotation != null) {
return new ControllerInfo(ip, port, type, annotation);
}
return new ControllerInfo(ip, port, type);
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class ControllerConfigCiscoImpl method parseControllerInfo.
private List<ControllerInfo> parseControllerInfo(String data) {
final String regex = "(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}):(\\d{1,5})";
Pattern pattern = Pattern.compile(regex);
Matcher match = pattern.matcher(data);
List<ControllerInfo> controllers = new ArrayList<ControllerInfo>();
while (match.find()) {
String str = match.group();
String[] ips = str.split(":");
ControllerInfo info = new ControllerInfo(IpAddress.valueOf(ips[0]), Integer.parseInt(ips[1]), "tcp");
controllers.add(info);
}
return controllers;
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class DefaultKubevirtNodeHandler method createPhysicalBridgeWithConnectedMode.
private void createPhysicalBridgeWithConnectedMode(KubevirtNode osNode, KubevirtPhyInterface phyInterface) {
Device device = deviceService.getDevice(osNode.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 = phyInterface.physBridge().toString().substring(DPID_BEGIN);
String bridgeName = BRIDGE_PREFIX + phyInterface.network();
BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(bridgeName).failMode(BridgeDescription.FailMode.SECURE).datapathId(dpid).mcastSnoopingEnable().disableInBand().controllers(controllers);
BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
bridgeConfig.addBridge(builder.build());
}
use of org.onosproject.net.behaviour.ControllerInfo in project onos by opennetworkinglab.
the class OpenstackNodeJsonMatcher method matchesSafely.
@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
// check hostname
String jsonHostname = jsonNode.get(Constants.HOST_NAME).asText();
String hostname = node.hostname();
if (!jsonHostname.equals(hostname)) {
description.appendText("hostname was " + jsonHostname);
return false;
}
// check type
String jsonType = jsonNode.get(Constants.TYPE).asText();
String type = node.type().name();
if (!jsonType.equals(type)) {
description.appendText("type was " + jsonType);
return false;
}
// check management IP
String jsonMgmtIp = jsonNode.get(MANAGEMENT_IP).asText();
String mgmtIp = node.managementIp().toString();
if (!jsonMgmtIp.equals(mgmtIp)) {
description.appendText("management IP was " + jsonMgmtIp);
return false;
}
// check integration bridge
JsonNode jsonIntgBridge = jsonNode.get(INTEGRATION_BRIDGE);
if (jsonIntgBridge != null) {
String intgBridge = node.intgBridge().toString();
if (!jsonIntgBridge.asText().equals(intgBridge)) {
description.appendText("integration bridge was " + jsonIntgBridge);
return false;
}
}
// check state
String jsonState = jsonNode.get(STATE).asText();
String state = node.state().name();
if (!jsonState.equals(state)) {
description.appendText("state was " + jsonState);
return false;
}
// check VLAN interface
JsonNode jsonVlanIntf = jsonNode.get(VLAN_INTF_NAME);
if (jsonVlanIntf != null) {
String vlanIntf = node.vlanIntf();
if (!jsonVlanIntf.asText().equals(vlanIntf)) {
description.appendText("VLAN interface was " + jsonVlanIntf.asText());
return false;
}
}
// check data IP
JsonNode jsonDataIp = jsonNode.get(DATA_IP);
if (jsonDataIp != null) {
String dataIp = node.dataIp().toString();
if (!jsonDataIp.asText().equals(dataIp)) {
description.appendText("Data IP was " + jsonDataIp.asText());
return false;
}
}
// check openstack ssh auth
JsonNode jsonSshAuth = jsonNode.get(SSH_AUTH);
if (jsonSshAuth != null) {
OpenstackSshAuth sshAuth = node.sshAuthInfo();
OpenstackSshAuthJsonMatcher sshAuthJsonMatcher = OpenstackSshAuthJsonMatcher.matchOpenstackSshAuth(sshAuth);
if (!sshAuthJsonMatcher.matches(jsonSshAuth)) {
return false;
}
}
// check dpdk config
JsonNode jsonDpdkConfig = jsonNode.get(DPDK_CONFIG);
if (jsonDpdkConfig != null) {
DpdkConfig dpdkConfig = node.dpdkConfig();
}
// check physical interfaces
JsonNode jsonPhyIntfs = jsonNode.get(PHYSICAL_INTERFACES);
if (jsonPhyIntfs != null) {
if (jsonPhyIntfs.size() != node.phyIntfs().size()) {
description.appendText("physical interface size was " + jsonPhyIntfs.size());
return false;
}
for (OpenstackPhyInterface phyIntf : node.phyIntfs()) {
boolean intfFound = false;
for (int intfIndex = 0; intfIndex < jsonPhyIntfs.size(); intfIndex++) {
OpenstackPhyInterfaceJsonMatcher intfMatcher = OpenstackPhyInterfaceJsonMatcher.matchesOpenstackPhyInterface(phyIntf);
if (intfMatcher.matches(jsonPhyIntfs.get(intfIndex))) {
intfFound = true;
break;
}
}
if (!intfFound) {
description.appendText("PhyIntf not found " + phyIntf.toString());
return false;
}
}
}
// check controllers
JsonNode jsonControllers = jsonNode.get(CONTROLLERS);
if (jsonControllers != null) {
if (jsonControllers.size() != node.controllers().size()) {
description.appendText("controllers size was " + jsonControllers.size());
return false;
}
for (ControllerInfo controller : node.controllers()) {
boolean ctrlFound = false;
for (int ctrlIndex = 0; ctrlIndex < jsonControllers.size(); ctrlIndex++) {
OpenstackControllerJsonMatcher ctrlMatcher = OpenstackControllerJsonMatcher.matchesOpenstackController(controller);
if (ctrlMatcher.matches(jsonControllers.get(ctrlIndex))) {
ctrlFound = true;
break;
}
}
if (!ctrlFound) {
description.appendText("Controller not found " + controller.toString());
return false;
}
}
}
return true;
}
Aggregations