use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method getFlowEntry.
@Override
public FlowEntry getFlowEntry(NetworkId networkId, FlowRule rule) {
MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
NodeId master = mastershipService.getMasterFor(rule.deviceId());
if (master == null) {
log.debug("Failed to getFlowEntry: No master for {}, vnet {}", rule.deviceId(), networkId);
return null;
}
if (Objects.equals(local, master)) {
return flowTable.getFlowEntry(networkId, rule);
}
log.trace("Forwarding getFlowEntry to {}, which is the primary (master) " + "for device {}, vnet {}", master, rule.deviceId(), networkId);
VirtualFlowRule vRule = new VirtualFlowRule(networkId, rule);
return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(vRule, GET_FLOW_ENTRY, serializer::encode, serializer::decode, master), FLOW_RULE_STORE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method addOrUpdateFlowRule.
@Override
public FlowRuleEvent addOrUpdateFlowRule(NetworkId networkId, FlowEntry rule) {
MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
NodeId master = mastershipService.getMasterFor(rule.deviceId());
if (Objects.equals(local, master)) {
return addOrUpdateFlowRuleInternal(networkId, rule);
}
log.warn("Tried to update FlowRule {} state," + " while the Node was not the master.", rule);
return null;
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method removeFlowRule.
@Override
public FlowRuleEvent removeFlowRule(NetworkId networkId, FlowEntry rule) {
final DeviceId deviceId = rule.deviceId();
MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
NodeId master = mastershipService.getMasterFor(deviceId);
if (Objects.equals(local, master)) {
// bypass and handle it locally
return removeFlowRuleInternal(new VirtualFlowEntry(networkId, rule));
}
if (master == null) {
log.warn("Failed to removeFlowRule: No master for {}", deviceId);
// TODO: revisit if this should be null (="no-op") or Exception
return null;
}
log.trace("Forwarding removeFlowRule to {}, which is the master for device {}", master, deviceId);
return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new VirtualFlowEntry(networkId, rule), REMOVE_FLOW_ENTRY, serializer::encode, serializer::decode, master));
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method storeBatch.
@Override
public void storeBatch(NetworkId networkId, FlowRuleBatchOperation operation) {
if (operation.getOperations().isEmpty()) {
notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId())));
return;
}
DeviceId deviceId = operation.deviceId();
MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
NodeId master = mastershipService.getMasterFor(deviceId);
if (master == null) {
log.warn("No master for {}, vnet {} : flows will be marked for removal", deviceId, networkId);
updateStoreInternal(networkId, operation);
notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), operation.deviceId())));
return;
}
if (Objects.equals(local, master)) {
storeBatchInternal(networkId, operation);
return;
}
log.trace("Forwarding storeBatch to {}, which is the primary (master) for device {}, vent {}", master, deviceId, networkId);
clusterCommunicator.unicast(new VirtualFlowRuleBatchOperation(networkId, operation), APPLY_BATCH_FLOWS, serializer::encode, master).whenComplete((result, error) -> {
if (error != null) {
log.warn("Failed to storeBatch: {} to {}", operation, master, error);
Set<FlowRule> allFailures = operation.getOperations().stream().map(BatchOperationEntry::target).collect(Collectors.toSet());
notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(false, allFailures, deviceId)));
}
});
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class ServerControllerConfig method getControllers.
@Override
public List<ControllerInfo> getControllers() {
List<ControllerInfo> controllers = Lists.newArrayList();
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
MastershipService mastershipService = getHandler().get(MastershipService.class);
checkNotNull(mastershipService, MSG_MASTERSHIP_NULL);
if (!mastershipService.isLocalMaster(deviceId)) {
log.warn("I am not master for {}. " + "Please use master {} to get controllers for this device", deviceId, mastershipService.getMasterFor(deviceId));
return controllers;
}
// Hit the path that provides the server's controllers
InputStream response = null;
try {
response = getController().get(deviceId, URL_CONTROLLERS_GET, JSON);
} catch (ProcessingException pEx) {
log.error("Failed to get controllers of device: {}", deviceId);
return controllers;
}
// Load the JSON into objects
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonMap = null;
JsonNode jsonNode = null;
ObjectNode objNode = null;
try {
jsonMap = mapper.readValue(response, Map.class);
jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
objNode = (ObjectNode) jsonNode;
} catch (IOException ioEx) {
log.error("Failed to get controllers of device: {}", deviceId);
return controllers;
}
if (jsonMap == null) {
log.error("Failed to get controllers of device: {}", deviceId);
return controllers;
}
// Fetch controllers' array
JsonNode ctrlNode = objNode.path(PARAM_CTRL);
for (JsonNode cn : ctrlNode) {
ObjectNode ctrlObjNode = (ObjectNode) cn;
// Get the attributes of a controller
String ctrlIpStr = get(cn, PARAM_CTRL_IP);
int ctrlPort = ctrlObjNode.path(PARAM_CTRL_PORT).asInt();
String ctrlType = get(cn, PARAM_CTRL_TYPE);
// Implies no controller
if (ctrlIpStr.isEmpty()) {
continue;
}
// Check data format and range
IpAddress ctrlIp = null;
try {
ctrlIp = IpAddress.valueOf(ctrlIpStr);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(e);
}
if ((ctrlPort < 0) || (ctrlPort > TpPort.MAX_PORT)) {
final String msg = "Invalid controller port: " + ctrlPort;
throw new IllegalArgumentException(msg);
}
controllers.add(new ControllerInfo(ctrlIp, ctrlPort, ctrlType));
}
return controllers;
}
Aggregations