Commit e3861e25 authored by Fernando Agraz's avatar Fernando Agraz
Browse files

Moved some Control Plane stuff to the Control Plane module. Need to replace...

Moved some Control Plane stuff to the Control Plane module. Need to replace the QoSControl with a REST Client. Need to solve compilation errors
parent f8d1a8d8
package edu.upc.gco.slcnt.cp.adapters;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.upc.gco.slcnt.cp.adapters.tech.FlexRAN;
import edu.upc.gco.slcnt.cp.adapters.tech.RANType;
import edu.upc.gco.slcnt.cp.cps.Configuration;
import edu.upc.gco.slcnt.qoe.optimizer.cp.CPSR;
/*
* RAN ADAPTER API:
*
* - List Slices
* - Create Slice
* - Configure: Slice, Cell, UE
* - Add access resources to Slice
* - Collect Metrics: Slice, Cell, UE
* - Add QoS Constraints
*/
public class RAN {
private Log logger = LogFactory.getLog(RAN.class);
public void increaseBandwidth (String sliceId, int value, RANType ranType)
{
switch (ranType)
{
case FlexRAN:
FlexRAN fr = new FlexRAN("http://193.55.112.80", "9999");
fr.initFlexRAN(sliceId);
//fr.setBandwidth(sliceId, value);
fr.createSlice(sliceId, value);
break;
default:
break;
}
}
public void configureSlice (String sliceId, Configuration config, RANType ranType)
{
switch (config.getType())
{
case BW:
{
switch (ranType)
{
case FlexRAN:
/*
FlexRAN fr = new FlexRAN("http://192.168.99.10", "9999");
fr.initFlexRAN(sliceId);
fr.setBandwidth(sliceId, Integer.parseInt(config.getValue()));
*/
logger.info("Configure Slice " + sliceId + ": Increase BW -> " + config.getValue());
break;
default:
break;
}
break;
}
default:
break;
}
}
}
package edu.upc.gco.slcnt.cp.adapters.tech;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.upc.gco.slcnt.cp.adapters.tech.flexran.DL;
import edu.upc.gco.slcnt.cp.adapters.tech.flexran.SliceConfig;
import edu.upc.gco.slcnt.cp.adapters.tech.flexran.UL;
public class FlexRAN {
private String controllerUri = "http://192.168.99.10";
private String controllerPort = "9999";
private HashSet<String> agentIds;
private HashSet<String> enbIds;
private Log logger = LogFactory.getLog(FlexRAN.class);
public FlexRAN()
{
this.agentIds = new HashSet<String>();
this.enbIds = new HashSet<String>();
}
public FlexRAN(String uri, String port)
{
this.controllerUri = uri;
this.controllerPort = port;
this.agentIds = new HashSet<String>();
this.enbIds = new HashSet<String>();
}
private ClientHttpRequestFactory getClientHttpRequestFactory()
{
int timeout = 2000;
HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory();
clientHttpRequestFactory.setConnectTimeout(timeout);
clientHttpRequestFactory.setConnectionRequestTimeout(timeout);
clientHttpRequestFactory.setReadTimeout(timeout);
return clientHttpRequestFactory;
}
private JsonNode getENBStats()
{
JsonNode root = null;
String url = this.controllerUri + ":" + this.controllerPort + "/stats";//"http://193.55.112.80:9999/stats/enb_config";
RestTemplate rt = new RestTemplate(this.getClientHttpRequestFactory());
String cpfURI = "";
try
{
cpfURI = rt.getForObject(url, String.class);
}
catch (RestClientException rce)
{
logger.error(rce.getMessage());
return root;
}
ObjectMapper mapper = new ObjectMapper();
try {
root = mapper.readTree(cpfURI);
//JsonNode uri = root.get("eNB_config");
//if (uri.isArray())
// strURI = "" + uri.get(0).get("eNBId").asInt();
} catch (IOException e) {
logger.error("Error processing the request: " + e.getMessage());
}
return root;
}
private void modifySlice(String agentId, SliceConfig sliceconfig) {
String uri = this.controllerUri + ":" + this.controllerPort + "/slice/enb/" + agentId;
logger.info("POST " + uri);
RestTemplate rt = new RestTemplate(this.getClientHttpRequestFactory());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<SliceConfig> sliceJson = new HttpEntity<>(sliceconfig);
String msg = "";
try {
msg = rt.postForObject(uri, sliceJson, String.class);
} catch (RestClientException rce) {
logger.error(rce.getMessage());
}
logger.info("Spring Return msg = " + msg);
/*
String json = null;
ObjectMapper mapper = new ObjectMapper();
try {
json = mapper.writeValueAsString(sliceconfig);
HttpURLConnection connection = null;
URL url = new URL(uri);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Length", Integer.toString(json.getBytes().length));
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream (connection.getOutputStream());
wr.writeBytes(json);
wr.close();
int code = connection.getResponseCode();
logger.info("Http Return code = " + code);
} catch (Exception e) {
e.printStackTrace();
}
*/
}
public void initFlexRAN (String sliceId)
{
JsonNode root = this.getENBStats();
JsonNode enbs = root.get("eNB_config");
logger.info("Processing: " + enbs.toString());
if (enbs.isArray())
{
for (JsonNode enbConf : enbs)
{
String agentId = enbConf.get("agent_id").asText();
String enbId = enbConf.get("eNBId").asText();
logger.info("Processing: " + agentId + " / " + enbId);
JsonNode enb = enbConf.get("eNB");
JsonNode cells = enb.get("cellConfig");
if (cells.isArray())
{
for (JsonNode cell : cells)
{
JsonNode sliceConf= cell.get("sliceConfig");
JsonNode slices = sliceConf.get("dl");
if (slices.isArray())
{
for (JsonNode slice : slices)
{
logger.info("Processing: Slice Id " + slice.get("id").asText());
if (slice.get("id").asText().equals(sliceId))
{
this.agentIds.add(agentId);
logger.info("Adding Agent " + agentId);
this.enbIds.add(enbId);
logger.info("Adding eNB " + enbId);
}
}
}
}
}
}
}
}
private boolean enoughBandwitdh (int size)
{
int usedBw = 0;
JsonNode root = this.getENBStats();
JsonNode enbs = root.get("eNB_config");
if (enbs.isArray())
{
for (JsonNode enbConf : enbs)
{
JsonNode enb = enbConf.get("eNB");
JsonNode cells = enb.get("cellConfig");
if (cells.isArray())
{
for (JsonNode cell : cells)
{
JsonNode sliceConf= cell.get("sliceConfig");
JsonNode uls = sliceConf.get("ul");
if (uls.isArray())
{
for (JsonNode ul : uls)
usedBw += ul.get("percentage").asInt();
}
}
}
}
}
logger.info("Used bw = " + usedBw);
return ((usedBw + size) <= 100);
}
private int getFreeSlot (int size)
{
int slot = 0;
JsonNode root = this.getENBStats();
JsonNode enbs = root.get("eNB_config");
if (enbs.isArray())
{
for (JsonNode enbConf : enbs)
{
JsonNode enb = enbConf.get("eNB");
JsonNode cells = enb.get("cellConfig");
if (cells.isArray())
{
for (JsonNode cell : cells)
{
JsonNode sliceConf= cell.get("sliceConfig");
JsonNode uls = sliceConf.get("ul");
if (uls.isArray())
{
for (JsonNode ul : uls)
{
int frb = ul.get("firstRb").asInt();
int prcntg = ul.get("percentage").asInt();
if (slot <= frb)
slot = frb + prcntg + 1;
else
slot += prcntg + 1;
}
}
}
}
}
}
return slot;
}
public void createSlice (String sliceId, int bandwidth)
{
logger.info("Creating Slice " + sliceId + " with initial bw = " + bandwidth);
if (!this.enoughBandwitdh(bandwidth))
return;
logger.info("Initial slot = " + this.getFreeSlot(bandwidth));
/*int isliceId = Integer.parseInt(sliceId);
DL dl = new DL (isliceId, null, bandwidth, null, null, null, null, null, null, null, null);
UL ul = new UL(isliceId, null, bandwidth, null, null, this.getFreeSlot(bandwidth), null, null, null);
ArrayList<DL> dls = new ArrayList<DL>(0);
dls.add(dl);
ArrayList<UL> uls = new ArrayList<UL>(0);
uls.add(ul);
SliceConfig sliceconfig = new SliceConfig(dls,uls,false,false);
for (String agent : this.agentIds)
{
this.modifySlice(agent, sliceconfig);
}*/
}
public void setBandwidth (String sliceId, int value)
{
logger.info("Setting BW to " + value + " in Slice " + sliceId);
int isliceId = Integer.parseInt(sliceId);
DL dl = new DL (isliceId, null, value, null, null, null, null, null, null, null, null);
UL ul = new UL(isliceId, null, value, null, null, null, null, null, null);
ArrayList<DL> dls = new ArrayList<DL>(0);
dls.add(dl);
ArrayList<UL> uls = new ArrayList<UL>(0);
uls.add(ul);
SliceConfig sliceconfig = new SliceConfig(dls,uls,false,false);
for (String agent : this.agentIds)
{
this.modifySlice(agent, sliceconfig);
}
}
public HashSet<String> getAgentIds() {
return agentIds;
}
public void setAgentIds(HashSet<String> agentIds) {
this.agentIds = agentIds;
}
public HashSet<String> getEnbIds() {
return enbIds;
}
public void setEnbIds(HashSet<String> enbIds) {
this.enbIds = enbIds;
}
}
package edu.upc.gco.slcnt.cp.adapters.tech;
public enum MECTye {
LLMEC,
UWS,
}
package edu.upc.gco.slcnt.cp.adapters.tech;
public enum RANType {
FlexRAN;
}
package edu.upc.gco.slcnt.cp.adapters.tech.flexran;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonInclude(Include.NON_NULL)
public class DL {
private Integer id;
private String label;
private Integer percentage;
private Boolean isolation;
private Integer priority;
private Integer positionLow;
private Integer positionHigh;
private Integer maxmcs;
private String[] sorting;
private String accounting;
private String schedulerName;
public DL() {
}
public DL(Integer id, String label, Integer percentage, Boolean isolation, Integer priority, Integer positionLow, Integer positionHigh,
Integer maxmcs, String[] sorting, String accounting, String schedulerName) {
this.id = id;
this.label = label;
this.percentage = percentage;
this.isolation = isolation;
this.priority = priority;
this.positionLow = positionLow;
this.positionHigh = positionHigh;
this.maxmcs = maxmcs;
this.sorting = sorting;
this.accounting = accounting;
this.schedulerName = schedulerName;
}
public Integer getID() {
return id;
}
public void setID(int id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Integer getPercentage() {
return percentage;
}
public void setPercentage(int percentage) {
this.percentage = percentage;
}
public Boolean isIsolation() {
return isolation;
}
public void setIsolation(boolean isolation) {
this.isolation = isolation;
}
public Integer getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public Integer getPositionLow() {
return positionLow;
}
public void setPositionLow(int positionLow) {
this.positionLow = positionLow;
}
public Integer getPositionHigh() {
return positionHigh;
}
public void setPositionHigh(int positionHigh) {
this.positionHigh = positionHigh;
}
public Integer getMaxmcs() {
return maxmcs;
}
public void setMaxmcs(int maxmcs) {
this.maxmcs = maxmcs;
}
public String[] getSorting() {
return sorting;
}
public void setSorting(String[] sorting) {
this.sorting = sorting;
}
public String getAccounting() {
return accounting;
}
public void setAccounting(String accounting) {
this.accounting = accounting;
}
public String getSchedulerName() {
return schedulerName;
}
public void setSchedulerName(String schedulerName) {
this.schedulerName = schedulerName;
}
}
package edu.upc.gco.slcnt.cp.adapters.tech.flexran;
import java.util.ArrayList;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonInclude(Include.NON_NULL)
public class SliceConfig {
private ArrayList<DL> dl;
private ArrayList<UL> ul;
private Boolean intrasliceShareActive;
private Boolean intersliceShareActive;
public SliceConfig() {
dl = new ArrayList<DL>(0);
ul = new ArrayList<UL>(0);
}
public SliceConfig(ArrayList<DL> dl, ArrayList<UL> ul, Boolean intrasliceShareActive,
Boolean intersliceShareActive) {
this.dl = dl;
this.ul = ul;
this.intrasliceShareActive = intrasliceShareActive;
this.intersliceShareActive = intersliceShareActive;
}
public ArrayList<DL> getDL() {
return dl;
}
public void setDl(ArrayList<DL> dl) {
this.dl = dl;
}
public void addDL(DL d) {
dl.add(d);
}
public ArrayList<UL> getUL() {
return ul;
}
public void setUL(ArrayList<UL> ul) {
this.ul = ul;
}
public void addUL(UL u) {
ul.add(u);
}
public Boolean isIntrasliceShareActive() {
return intrasliceShareActive;
}
public void setIntrasliceShareActive(boolean intrasliceShareActive) {
this.intrasliceShareActive = intrasliceShareActive;
}
public Boolean isIntersliceShareActive() {
return intersliceShareActive;
}
public void setIntersliceShareActive(boolean intersliceShareActive) {
this.intersliceShareActive = intersliceShareActive;