blob: 59232044865e0616bdca5aeedae157400f5164e4 [file] [log] [blame]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +00001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.opencord.sadis.impl;
17
18import java.io.IOException;
19import java.util.ArrayList;
20import java.util.List;
21
22import org.onlab.packet.Ip4Address;
Matteo Scandolo198aef92020-01-08 00:43:17 +000023import org.onlab.packet.MacAddress;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000024import org.onlab.packet.VlanId;
25import org.opencord.sadis.BaseConfig;
26import org.opencord.sadis.SubscriberAndDeviceInformation;
27
Matteo Scandolo198aef92020-01-08 00:43:17 +000028import org.opencord.sadis.UniTagInformation;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000029import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import com.fasterxml.jackson.core.JsonParser;
33import com.fasterxml.jackson.core.ObjectCodec;
34import com.fasterxml.jackson.databind.DeserializationContext;
35import com.fasterxml.jackson.databind.JsonDeserializer;
36import com.fasterxml.jackson.databind.JsonNode;
37import com.fasterxml.jackson.databind.ObjectMapper;
38import com.fasterxml.jackson.databind.module.SimpleModule;
39
40/**
41 * Configuration options for the Subscriber And Device Information Service.
42 *
43 * <pre>
44 * "sadis" : {
45 * "integration" : {
46 * "url" : "http://{hostname}{:port}",
47 * "cache" : {
48 * "maxsize" : number of entries,
49 * "entryttl" : duration, i.e. 10s or 1m
50 * }
51 * },
52 * "entries" : [
53 * {
54 * "id" : "uniqueid",
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000055 * "nasportid" : string,
56 * "port" : int,
57 * "slot" : int,
58 * "hardwareidentifier" : string,
59 * "ipAddress" : string,
60 * "nasId" : string,
61 * "circuitId" : string,
Matteo Scandolo198aef92020-01-08 00:43:17 +000062 * "remoteId" : string,
63 * "uniTagList": [
64 * {
yasin sapli2c93ddb2021-06-11 17:46:26 +030065 * "uniTagMatch" : int,
66 * "ponCTag" : string,
67 * "ponSTag" : string,
68 * "usPonCTagPriority" : int,
69 * "dsPonCTagPriority" : int,
70 * "usPonSTagPriority" : int,
71 * "dsPonSTagPriority" : int,
72 * "technologyProfileId" : int,
73 * "upstreamBandwidthProfile" : string,
74 * "downstreamBandwidthProfile" : string,
75 * "upstreamOltBandwidthProfile" : string,
76 * "downstreamOltBandwidthProfile" : string,
77 * "enableMacLearning" : string,
78 * "configuredDacAddress" : string,
79 * "isDhcpRequired" : string,
80 * "isIgmpRequired" : string,
yasin sapli9e3ebed2021-07-09 14:06:35 +000081 * "isPppoeRequired" : string,
yasin sapli2c93ddb2021-06-11 17:46:26 +030082 * "serviceName" : string
Matteo Scandolo198aef92020-01-08 00:43:17 +000083 * }
yasin sapli2c93ddb2021-06-11 17:46:26 +030084 * ]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000085 * }, ...
86 * ]
87 * }
88 * </pre>
89 */
90public class SubscriberAndDeviceInformationConfig extends BaseConfig<SubscriberAndDeviceInformation> {
91
92 private final Logger log = LoggerFactory.getLogger(this.getClass());
Matteo Scandolo198aef92020-01-08 00:43:17 +000093 private static final int NO_PCP = -1;
Andrea Campanella30041b92022-01-28 16:09:08 +010094 private static final int NO_TP = -1;
Matteo Scandolo198aef92020-01-08 00:43:17 +000095 private static final String NO_SN = "";
96 private static final String UNI_TAG_MATCH = "uniTagMatch";
97 private static final String PON_C_TAG = "ponCTag";
98 private static final String PON_S_TAG = "ponSTag";
99 private static final String US_C_TAG_PCP = "usPonCTagPriority";
100 private static final String US_S_TAG_PCP = "usPonSTagPriority";
101 private static final String DS_C_TAG_PCP = "dsPonCTagPriority";
102 private static final String DS_S_TAG_PCP = "dsPonSTagPriority";
103 private static final String MAC_LEARNING = "enableMacLearning";
104 private static final String TP_ID = "technologyProfileId";
105 private static final String US_BW = "upstreamBandwidthProfile";
106 private static final String DS_BW = "downstreamBandwidthProfile";
yasin sapli2c93ddb2021-06-11 17:46:26 +0300107 private static final String US_OLT_BW = "upstreamOltBandwidthProfile";
108 private static final String DS_OLT_BW = "downstreamOltBandwidthProfile";
Matteo Scandolo198aef92020-01-08 00:43:17 +0000109 private static final String SERVICE_NAME = "serviceName";
110 private static final String IS_DHCP_REQ = "isDhcpRequired";
111 private static final String IS_IGMP_REQ = "isIgmpRequired";
yasin sapli9e3ebed2021-07-09 14:06:35 +0000112 private static final String IS_PPPOE_REQ = "isPppoeRequired";
Matteo Scandolo198aef92020-01-08 00:43:17 +0000113 private static final String MAC_ADDRESS = "configuredMacAddress";
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000114
115 public List<SubscriberAndDeviceInformation> getEntries() {
116 List<SubscriberAndDeviceInformation> result = new ArrayList<>();
117 ObjectMapper mapper = new ObjectMapper();
118 SimpleModule module = new SimpleModule();
119 module.addDeserializer(VlanId.class, new VlanIdDeserializer());
120 module.addDeserializer(Ip4Address.class, new Ip4AddressDeserializer());
Matteo Scandolo198aef92020-01-08 00:43:17 +0000121 module.addDeserializer(UniTagInformation.class, new UniTagDeserializer());
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000122 mapper.registerModule(module);
123 final JsonNode entries = this.object.path(ENTRIES);
124 entries.forEach(entry -> {
125 try {
126 result.add(mapper.readValue(entry.toString(), SubscriberAndDeviceInformation.class));
127 } catch (IOException e) {
128 log.warn("Unable to parse configuration entry, '{}', error: {}", entry, e.getMessage());
129 }
130 });
131
132 return result;
133 }
134
135 public class VlanIdDeserializer extends JsonDeserializer<VlanId> {
136 @Override
137 public VlanId deserialize(JsonParser jp, DeserializationContext ctxt)
138 throws IOException {
139 ObjectCodec oc = jp.getCodec();
140 JsonNode node = oc.readTree(jp);
141 return VlanId.vlanId((short) node.asInt());
142 }
143 }
144
145 public class Ip4AddressDeserializer extends JsonDeserializer<Ip4Address> {
146 @Override
147 public Ip4Address deserialize(JsonParser jp, DeserializationContext ctxt)
148 throws IOException {
149 ObjectCodec oc = jp.getCodec();
150 JsonNode node = oc.readTree(jp);
151 return Ip4Address.valueOf(node.asText());
152 }
153 }
Matteo Scandolo198aef92020-01-08 00:43:17 +0000154
155 public class UniTagDeserializer extends JsonDeserializer<UniTagInformation> {
156 @Override
157 public UniTagInformation deserialize(JsonParser jp, DeserializationContext ctxt)
158 throws IOException {
159 ObjectCodec oc = jp.getCodec();
160 JsonNode node = oc.readTree(jp);
161 return getUniTagInformation(node);
162 }
163 }
164
165 public UniTagInformation getUniTagInformation(JsonNode node) {
yasin sapli2c93ddb2021-06-11 17:46:26 +0300166 String usBw = node.get(US_BW) == null ? null : node.get(US_BW).asText();
167 String dsBw = node.get(DS_BW) == null ? null : node.get(DS_BW).asText();
Matteo Scandolo198aef92020-01-08 00:43:17 +0000168 return new UniTagInformation.Builder()
169 .setUniTagMatch(VlanId.vlanId(node.get(UNI_TAG_MATCH) == null ? VlanId.NO_VID
170 : (short) node.get(UNI_TAG_MATCH).asInt()))
Andrea Campanella30041b92022-01-28 16:09:08 +0100171 .setPonCTag(node.get(PON_C_TAG) == null ? VlanId.vlanId(VlanId.NO_VID) :
172 VlanId.vlanId(node.get(PON_C_TAG).shortValue()))
173 .setPonSTag(node.get(PON_S_TAG) == null ? VlanId.vlanId(VlanId.NO_VID) :
174 VlanId.vlanId(node.get(PON_S_TAG).shortValue()))
Matteo Scandolo198aef92020-01-08 00:43:17 +0000175 .setUsPonCTagPriority(node.get(US_C_TAG_PCP) == null ? NO_PCP :
176 node.get(US_C_TAG_PCP).asInt())
177 .setUsPonSTagPriority(node.get(US_S_TAG_PCP) == null ? NO_PCP :
178 node.get(US_S_TAG_PCP).asInt())
179 .setDsPonCTagPriority(node.get(DS_C_TAG_PCP) == null ? NO_PCP :
180 node.get(DS_C_TAG_PCP).asInt())
181 .setDsPonSTagPriority(node.get(DS_S_TAG_PCP) == null ? NO_PCP :
182 node.get(DS_S_TAG_PCP).asInt())
Andrea Campanella30041b92022-01-28 16:09:08 +0100183 .setEnableMacLearning(node.get(MAC_LEARNING) != null && node.get(MAC_LEARNING).asBoolean())
184 .setTechnologyProfileId(node.get(TP_ID) == null ? NO_TP : node.get(TP_ID).asInt())
yasin sapli2c93ddb2021-06-11 17:46:26 +0300185 .setUpstreamBandwidthProfile(usBw)
186 .setDownstreamBandwidthProfile(dsBw)
187 .setUpstreamOltBandwidthProfile(node.get(US_OLT_BW) == null ? usBw
188 : node.get(US_OLT_BW).asText())
189 .setDownstreamOltBandwidthProfile(node.get(DS_OLT_BW) == null ? dsBw
190 : node.get(DS_OLT_BW).asText())
Matteo Scandolo198aef92020-01-08 00:43:17 +0000191 .setServiceName(node.get(SERVICE_NAME) == null ? NO_SN :
192 node.get(SERVICE_NAME).asText())
Andrea Campanella30041b92022-01-28 16:09:08 +0100193 .setIsDhcpRequired(node.get(IS_DHCP_REQ) != null && node.get(IS_DHCP_REQ).asBoolean())
194 .setIsIgmpRequired(node.get(IS_IGMP_REQ) != null && node.get(IS_IGMP_REQ).asBoolean())
yasin sapli9e3ebed2021-07-09 14:06:35 +0000195 .setIsPppoeRequired(node.get(IS_PPPOE_REQ) != null && node.get(IS_PPPOE_REQ).asBoolean())
Matteo Scandolo198aef92020-01-08 00:43:17 +0000196 .setConfiguredMacAddress(node.get(MAC_ADDRESS) == null ? MacAddress.NONE.toString() :
197 node.get(MAC_ADDRESS).asText())
198 .build();
199 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000200}