blob: 5f59d4d11338c1c80e6051a15c97c3544b934e5c [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
2 * Copyright 2015-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.xran.impl;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import org.apache.commons.lang.exception.ExceptionUtils;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.config.Config;
24import org.onosproject.xran.codecs.api.ECGI;
25import org.onosproject.xran.codecs.api.EUTRANCellIdentifier;
26import org.onosproject.xran.codecs.api.PLMNIdentity;
27import org.openmuc.jasn1.util.HexConverter;
28import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
30
31import javax.xml.bind.DatatypeConverter;
32import java.io.ByteArrayInputStream;
33import java.io.IOException;
34import java.io.InputStream;
35import java.net.URI;
36import java.net.URISyntaxException;
37import java.util.Map;
38import java.util.concurrent.ConcurrentHashMap;
39
40import static org.onosproject.net.DeviceId.deviceId;
41
42public class XranConfig extends Config<ApplicationId> {
43
44 private static final String CELLS = "active_cells";
45
46 private static final String PLMN_ID = "plmn_id";
47 private static final String ECI_ID = "eci";
48
49 private static final String IP_ADDR = "ip_addr";
50
51 private static final String XRANC_PORT = "xranc_port";
52
53 private static final String XRANC_CELLCONFIG_INTERVAL = "xranc_cellconfigrequest_interval_seconds";
54
55 private static final String RX_SIGNAL_MEAS_REPORT_INTERVAL = "rx_signal_meas_report_interval_seconds";
56
57 private static final String L2_MEAS_REPORT_INTERVAL = "l2_meas_report_interval_ms";
58
slowr8ddc2b12017-08-14 14:13:38 -070059 private static final String ADMISSION_SUCCESS = "admission_success";
60
61 private static final String BEARER_SUCCESS = "bearer_success";
62
slowr13fa5b02017-08-08 16:32:31 -070063 private final Logger log = LoggerFactory.getLogger(getClass());
64
65 public Map<String, ECGI> activeCellSet() {
66 Map<String, ECGI> cells = new ConcurrentHashMap<>();
67
68 JsonNode cellsNode = object.get(CELLS);
69 if (cellsNode == null) {
70 log.warn("no cells have been provided!");
71 return cells;
72 }
73
74 cellsNode.forEach(cellNode -> {
75 String plmn_id = cellNode.get(PLMN_ID).asText();
76 String eci = cellNode.get(ECI_ID).asText();
77
78 String ipAddress = cellNode.get(IP_ADDR).asText();
79
80 ECGI ecgi = hexToECGI(plmn_id, eci);
81 cells.put(ipAddress, ecgi);
82 });
83
84 return cells;
85 }
86
slowr8ddc2b12017-08-14 14:13:38 -070087 public boolean admissionFlag() {
88 JsonNode flag = object.get(ADMISSION_SUCCESS);
89 return flag != null && flag.asBoolean();
90 }
91
92 public boolean bearerFlag() {
93 JsonNode flag = object.get(BEARER_SUCCESS);
94 return flag != null && flag.asBoolean();
95 }
96
slowr13fa5b02017-08-08 16:32:31 -070097 public int getXrancPort() {
98 return object.get(XRANC_PORT).asInt();
99 }
100
101 public int getConfigRequestInterval() {
102 return object.get(XRANC_CELLCONFIG_INTERVAL).asInt();
103 }
104
105 public int getRxSignalInterval() {
106 return object.get(RX_SIGNAL_MEAS_REPORT_INTERVAL).asInt();
107 }
108
109 public int getL2MeasInterval() {
110 return object.get(L2_MEAS_REPORT_INTERVAL).asInt();
111 }
112
113
114 private ECGI hexToECGI(String plmn_id, String eci) {
115 byte[] bytes = HexConverter.fromShortHexString(plmn_id);
116 byte[] bytearray = DatatypeConverter.parseHexBinary(eci);
117
118 InputStream inputStream = new ByteArrayInputStream(bytearray);
119
120 PLMNIdentity plmnIdentity = new PLMNIdentity(bytes);
121 EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(bytearray, 28);
122
123 ECGI ecgi = new ECGI();
124 ecgi.setEUTRANcellIdentifier(eutranCellIdentifier);
125 ecgi.setPLMNIdentity(plmnIdentity);
126 try {
127 ecgi.decode(inputStream);
128 } catch (IOException e) {
129 e.printStackTrace();
130 }
131
132 return ecgi;
133 }
134}