use of org.onosproject.odtn.utils.tapi.TapiCreateConnectivityOutputHandler in project onos by opennetworkinglab.
the class DcsBasedTapiConnectivityRpc method createConnectivityService.
/**
* Service interface of createConnectivityService.
*
* @param inputVar input of service interface createConnectivityService
* @return output of service interface createConnectivityService
*/
@Override
public RpcOutput createConnectivityService(RpcInput inputVar) {
try {
TapiCreateConnectivityInputHandler input = new TapiCreateConnectivityInputHandler();
input.setRpcInput(inputVar);
log.info("input SIPs: {}", input.getSips());
// check SIP validation
if (!disjoint(getUsedSips(), input.getSips())) {
log.error("SIPS {} are already used, please use a different pair", input.getSips());
return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
}
log.debug("check SIP validation : OK");
List<TapiNepRef> nepRefs = input.getSips().stream().map(sipId -> resolver.getNepRef(sipId)).collect(Collectors.toList());
// setup connections
TapiNepPair neps = TapiNepPair.create(nepRefs.get(0), nepRefs.get(1));
// Allocate a connectivity Service
TapiConnectivityServiceHandler connectivityServiceHandler = TapiConnectivityServiceHandler.create();
// This connectivity service will be supported over a single end-to-end connection
// Allocate a manager for that connection
DcsBasedTapiConnectionManager connectionManager = DcsBasedTapiConnectionManager.create();
TapiConnectionHandler connectionHandler = connectionManager.createConnection(neps);
// Add the supporting connection uuid to the service
connectivityServiceHandler.addConnection(connectionHandler.getModelObject().uuid());
neps.stream().map(nepRef -> TapiSepHandler.create().setSip(nepRef.getSipId())).forEach(sepBuilder -> {
connectivityServiceHandler.addSep(sepBuilder.getModelObject());
});
// build
connectionManager.apply();
connectivityServiceHandler.add();
// output
TapiCreateConnectivityOutputHandler output = TapiCreateConnectivityOutputHandler.create().addService(connectivityServiceHandler.getModelObject());
return new RpcOutput(RpcOutput.Status.RPC_SUCCESS, output.getDataNode());
} catch (Throwable e) {
log.error("Error:", e);
return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
}
}
Aggregations