Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 1 | /* |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 2 | Copyright (C) 2018 Open Networking Foundation |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation, either version 3 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #include <iostream> |
| 19 | #include <memory> |
| 20 | #include <string> |
| 21 | |
| 22 | #include "Queue.h" |
| 23 | #include <iostream> |
| 24 | #include <sstream> |
| 25 | |
| 26 | #include "core.h" |
| 27 | #include "indications.h" |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 28 | #include "stats_collection.h" |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 29 | #include "error_format.h" |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 30 | |
| 31 | extern "C" |
| 32 | { |
| 33 | #include <bcmos_system.h> |
| 34 | #include <bal_api.h> |
| 35 | #include <bal_api_end.h> |
| 36 | } |
| 37 | |
| 38 | Status Enable_() { |
| 39 | static bool enabled = false; |
| 40 | bcmbal_access_terminal_cfg acc_term_obj; |
| 41 | bcmbal_access_terminal_key key = { }; |
| 42 | |
| 43 | if (!enabled) { |
| 44 | std::cout << "Enable OLT" << std::endl; |
| 45 | key.access_term_id = DEFAULT_ATERM_ID; |
| 46 | BCMBAL_CFG_INIT(&acc_term_obj, access_terminal, key); |
| 47 | BCMBAL_CFG_PROP_SET(&acc_term_obj, access_terminal, admin_state, BCMBAL_STATE_UP); |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 48 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(acc_term_obj.hdr)); |
| 49 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 50 | std::cout << "ERROR: Failed to enable OLT" << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 51 | return bcm_to_grpc_err(err, "Failed to enable OLT"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 52 | } |
| 53 | enabled = true; |
| 54 | } |
| 55 | return Status::OK; |
| 56 | } |
| 57 | |
| 58 | Status EnablePonIf_(uint32_t intf_id) { |
| 59 | bcmbal_interface_cfg interface_obj; |
| 60 | bcmbal_interface_key interface_key; |
| 61 | |
| 62 | interface_key.intf_id = intf_id; |
| 63 | interface_key.intf_type = BCMBAL_INTF_TYPE_PON; |
| 64 | |
| 65 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
| 66 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_UP); |
| 67 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 68 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 69 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 70 | std::cout << "ERROR: Failed to enable PON interface: " << intf_id << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 71 | return bcm_to_grpc_err(err, "Failed to enable PON interface"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | return Status::OK; |
| 75 | } |
| 76 | |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 77 | Status DisablePonIf_(uint32_t intf_id) { |
| 78 | bcmbal_interface_cfg interface_obj; |
| 79 | bcmbal_interface_key interface_key; |
| 80 | |
| 81 | interface_key.intf_id = intf_id; |
| 82 | interface_key.intf_type = BCMBAL_INTF_TYPE_PON; |
| 83 | |
| 84 | BCMBAL_CFG_INIT(&interface_obj, interface, interface_key); |
| 85 | BCMBAL_CFG_PROP_SET(&interface_obj, interface, admin_state, BCMBAL_STATE_DOWN); |
| 86 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 87 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(interface_obj.hdr)); |
| 88 | if (err) { |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 89 | std::cout << "ERROR: Failed to disable PON interface: " << intf_id << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 90 | return bcm_to_grpc_err(err, "Failed to disable PON interface"); |
Nicolas Palpacuer | 05ea0ea | 2018-07-06 11:47:21 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | return Status::OK; |
| 94 | } |
| 95 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 96 | Status ActivateOnu_(uint32_t intf_id, uint32_t onu_id, |
Shad Ansari | 0610195 | 2018-07-25 00:22:09 +0000 | [diff] [blame^] | 97 | const char *vendor_id, const char *vendor_specific, uint32_t pir) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 98 | |
| 99 | bcmbal_subscriber_terminal_cfg sub_term_obj = {}; |
| 100 | bcmbal_subscriber_terminal_key subs_terminal_key; |
| 101 | bcmbal_serial_number serial_num = {}; |
| 102 | bcmbal_registration_id registration_id = {}; |
| 103 | |
| 104 | std::cout << "Enabling ONU " << onu_id << " on PON " << intf_id << std::endl; |
| 105 | std::cout << "Vendor Id " << vendor_id |
| 106 | << "Vendor Specific Id " << vendor_specific |
Shad Ansari | 0610195 | 2018-07-25 00:22:09 +0000 | [diff] [blame^] | 107 | << "pir " << pir |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 108 | << std::endl; |
| 109 | |
| 110 | subs_terminal_key.sub_term_id = onu_id; |
| 111 | subs_terminal_key.intf_id = intf_id; |
| 112 | BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key); |
| 113 | |
| 114 | memcpy(serial_num.vendor_id, vendor_id, 4); |
| 115 | memcpy(serial_num.vendor_specific, vendor_specific, 4); |
| 116 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, serial_number, serial_num); |
| 117 | |
Shad Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 118 | #if 0 |
| 119 | // Commenting out as this is causing issues with onu activation |
| 120 | // with BAL 2.6 (Broadcom CS5248819). |
| 121 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 122 | // FIXME - Use a default (all zeros) registration id. |
| 123 | memset(registration_id.arr, 0, sizeof(registration_id.arr)); |
| 124 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, registration_id, registration_id); |
Shad Ansari | cb004c5 | 2018-05-30 18:07:23 +0000 | [diff] [blame] | 125 | #endif |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 126 | |
| 127 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_UP); |
| 128 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 129 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr)); |
| 130 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 131 | std::cout << "ERROR: Failed to enable ONU: " << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 132 | return bcm_to_grpc_err(err, "Failed to enable ONU"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Shad Ansari | 0610195 | 2018-07-25 00:22:09 +0000 | [diff] [blame^] | 135 | /* Create subscriber's tm_sched */ |
| 136 | { |
| 137 | bcmbal_tm_sched_cfg cfg; |
| 138 | bcmbal_tm_sched_key key = { }; |
| 139 | key.dir = BCMBAL_TM_SCHED_DIR_DS; |
| 140 | key.id = intf_id << 7 | onu_id; |
| 141 | BCMBAL_CFG_INIT(&cfg, tm_sched, key); |
| 142 | |
| 143 | bcmbal_tm_sched_owner owner = { }; |
| 144 | owner.type = BCMBAL_TM_SCHED_OWNER_TYPE_SUB_TERM; |
| 145 | owner.u.sub_term.intf_id = intf_id; |
| 146 | owner.u.sub_term.sub_term_id = onu_id; |
| 147 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, owner); |
| 148 | |
| 149 | bcmbal_tm_sched_parent parent = { }; |
| 150 | parent.sched_id = intf_id + 16384; |
| 151 | parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_SCHED_ID; |
| 152 | parent.weight = 1; |
| 153 | parent.presence_mask = parent.presence_mask | BCMBAL_TM_SCHED_PARENT_ID_WEIGHT; |
| 154 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_parent, parent); |
| 155 | |
| 156 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, sched_type, BCMBAL_TM_SCHED_TYPE_WFQ); |
| 157 | |
| 158 | bcmbal_tm_shaping shaping = { }; |
| 159 | shaping.pir = pir; |
| 160 | shaping.presence_mask = shaping.presence_mask | BCMBAL_TM_SHAPING_ID_PIR; |
| 161 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, rate, shaping); |
| 162 | |
| 163 | bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr); |
| 164 | } |
| 165 | |
| 166 | /* Create tm_queue */ |
| 167 | { |
| 168 | bcmbal_tm_queue_cfg cfg; |
| 169 | bcmbal_tm_queue_key key = { }; |
| 170 | key.sched_id = intf_id << 7 | onu_id; |
| 171 | key.sched_dir = BCMBAL_TM_SCHED_DIR_DS; |
| 172 | key.id = 0; |
| 173 | BCMBAL_CFG_INIT(&cfg, tm_queue, key); |
| 174 | BCMBAL_CFG_PROP_SET(&cfg, tm_queue, weight, 1); |
| 175 | bcmbal_cfg_set(DEFAULT_ATERM_ID, &cfg.hdr); |
| 176 | } |
| 177 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 178 | return SchedAdd_(intf_id, onu_id, mk_agg_port_id(onu_id)); |
| 179 | |
| 180 | //return Status::OK; |
| 181 | } |
| 182 | |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 183 | Status DeactivateOnu_(uint32_t intf_id, uint32_t onu_id, |
| 184 | const char *vendor_id, const char *vendor_specific) { |
| 185 | |
| 186 | SchedRemove_(intf_id, onu_id, mk_agg_port_id(onu_id)); |
| 187 | |
| 188 | bcmbal_subscriber_terminal_cfg sub_term_obj = {}; |
| 189 | bcmbal_subscriber_terminal_key subs_terminal_key; |
| 190 | |
| 191 | std::cout << "Deactivating ONU " << onu_id << " on PON " << intf_id << std::endl; |
| 192 | std::cout << "Vendor Id " << vendor_id |
| 193 | << "Vendor Specific Id " << vendor_specific |
| 194 | << std::endl; |
| 195 | |
| 196 | subs_terminal_key.sub_term_id = onu_id; |
| 197 | subs_terminal_key.intf_id = intf_id; |
| 198 | BCMBAL_CFG_INIT(&sub_term_obj, subscriber_terminal, subs_terminal_key); |
| 199 | |
| 200 | BCMBAL_CFG_PROP_SET(&sub_term_obj, subscriber_terminal, admin_state, BCMBAL_STATE_DOWN); |
| 201 | |
| 202 | if (bcmbal_cfg_set(DEFAULT_ATERM_ID, &(sub_term_obj.hdr))) { |
| 203 | std::cout << "ERROR: Failed to deactivate ONU: " << std::endl; |
| 204 | return Status(grpc::StatusCode::INTERNAL, "Failed to deactivate ONU"); |
| 205 | } |
| 206 | |
| 207 | return Status::OK; |
| 208 | } |
| 209 | |
| 210 | Status DeleteOnu_(uint32_t intf_id, uint32_t onu_id, |
| 211 | const char *vendor_id, const char *vendor_specific) { |
| 212 | bcmos_errno err = BCM_ERR_OK; |
| 213 | bcmbal_subscriber_terminal_cfg cfg; |
| 214 | bcmbal_subscriber_terminal_key key = { }; |
| 215 | |
| 216 | std::cout << "Processing subscriber terminal cfg clear for sub_term_id = " |
| 217 | << onu_id << " and intf_id = " << intf_id << std::endl; |
| 218 | |
| 219 | key.sub_term_id = onu_id ; |
| 220 | key.intf_id = intf_id ; |
| 221 | |
| 222 | if (0 == key.sub_term_id) |
| 223 | { |
| 224 | std::cout << "Invalid Key to handle subscriber terminal clear subscriber_terminal_id = " |
| 225 | << onu_id << " Interface ID = " << intf_id << std::endl; |
| 226 | return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU"); |
| 227 | } |
| 228 | |
| 229 | BCMBAL_CFG_INIT(&cfg, subscriber_terminal, key); |
| 230 | |
| 231 | err = bcmbal_cfg_clear(DEFAULT_ATERM_ID, &cfg.hdr); |
| 232 | if (err != BCM_ERR_OK) |
| 233 | { |
| 234 | std::cout << "Failed to clear information for BAL subscriber_terminal_id = " |
| 235 | << onu_id << " Interface ID = " << intf_id << std::endl; |
| 236 | return Status(grpc::StatusCode::INTERNAL, "Failed to delete ONU"); |
| 237 | } |
| 238 | |
| 239 | return Status::OK;; |
| 240 | } |
| 241 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 242 | #define MAX_CHAR_LENGTH 20 |
| 243 | #define MAX_OMCI_MSG_LENGTH 44 |
| 244 | Status OmciMsgOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) { |
| 245 | bcmbal_u8_list_u32_max_2048 buf; /* A structure with a msg pointer and length value */ |
| 246 | bcmos_errno err = BCM_ERR_OK; |
| 247 | |
| 248 | /* The destination of the OMCI packet is a registered ONU on the OLT PON interface */ |
| 249 | bcmbal_dest proxy_pkt_dest; |
| 250 | |
| 251 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_ITU_OMCI_CHANNEL; |
| 252 | proxy_pkt_dest.u.itu_omci_channel.sub_term_id = onu_id; |
| 253 | proxy_pkt_dest.u.itu_omci_channel.intf_id = intf_id; |
| 254 | |
| 255 | // ??? |
| 256 | if ((pkt.size()/2) > MAX_OMCI_MSG_LENGTH) { |
| 257 | buf.len = MAX_OMCI_MSG_LENGTH; |
| 258 | } else { |
| 259 | buf.len = pkt.size()/2; |
| 260 | } |
| 261 | |
| 262 | /* Send the OMCI packet using the BAL remote proxy API */ |
| 263 | uint16_t idx1 = 0; |
| 264 | uint16_t idx2 = 0; |
| 265 | uint8_t arraySend[buf.len]; |
| 266 | char str1[MAX_CHAR_LENGTH]; |
| 267 | char str2[MAX_CHAR_LENGTH]; |
| 268 | memset(&arraySend, 0, buf.len); |
| 269 | |
| 270 | std::cout << "Sending omci msg to ONU of length is " |
| 271 | << buf.len |
| 272 | << std::endl; |
| 273 | |
| 274 | for (idx1=0,idx2=0; idx1<((buf.len)*2); idx1++,idx2++) { |
| 275 | sprintf(str1,"%c", pkt[idx1]); |
| 276 | sprintf(str2,"%c", pkt[++idx1]); |
| 277 | strcat(str1,str2); |
| 278 | arraySend[idx2] = strtol(str1, NULL, 16); |
| 279 | } |
| 280 | |
| 281 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 282 | memcpy(buf.val, (uint8_t *)arraySend, buf.len); |
| 283 | |
| 284 | std::cout << "After converting bytes to hex " |
| 285 | << buf.val << buf.len << std::endl; |
| 286 | |
| 287 | err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len); |
| 288 | |
| 289 | std::cout << "OMCI request msg of length " << buf.len |
| 290 | << " sent to ONU" << onu_id |
| 291 | << " through PON " << intf_id << std::endl; |
| 292 | |
| 293 | free(buf.val); |
| 294 | |
| 295 | return Status::OK; |
| 296 | } |
| 297 | |
| 298 | Status OnuPacketOut_(uint32_t intf_id, uint32_t onu_id, const std::string pkt) { |
| 299 | bcmos_errno err = BCM_ERR_OK; |
| 300 | bcmbal_dest proxy_pkt_dest; |
| 301 | bcmbal_u8_list_u32_max_2048 buf; |
| 302 | |
| 303 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_SUB_TERM, |
| 304 | proxy_pkt_dest.u.sub_term.sub_term_id = onu_id; |
| 305 | proxy_pkt_dest.u.sub_term.intf_id = intf_id; |
| 306 | |
| 307 | buf.len = pkt.size(); |
| 308 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 309 | memcpy(buf.val, (uint8_t *)pkt.data(), buf.len); |
| 310 | |
| 311 | err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len); |
| 312 | |
| 313 | std::cout << "Packet out of length " << buf.len |
| 314 | << " sent to ONU" << onu_id |
| 315 | << " through PON " << intf_id << std::endl; |
| 316 | |
| 317 | free(buf.val); |
| 318 | |
| 319 | return Status::OK; |
| 320 | } |
| 321 | |
Nicolas Palpacuer | b78def4 | 2018-06-07 12:55:26 -0400 | [diff] [blame] | 322 | Status UplinkPacketOut_(uint32_t intf_id, const std::string pkt) { |
| 323 | bcmos_errno err = BCM_ERR_OK; |
| 324 | bcmbal_dest proxy_pkt_dest; |
| 325 | bcmbal_u8_list_u32_max_2048 buf; |
| 326 | |
| 327 | proxy_pkt_dest.type = BCMBAL_DEST_TYPE_NNI, |
| 328 | proxy_pkt_dest.u.nni.intf_id = intf_id; |
| 329 | |
| 330 | buf.len = pkt.size(); |
| 331 | buf.val = (uint8_t *)malloc((buf.len)*sizeof(uint8_t)); |
| 332 | memcpy(buf.val, (uint8_t *)pkt.data(), buf.len); |
| 333 | |
| 334 | err = bcmbal_pkt_send(0, proxy_pkt_dest, (const char *)(buf.val), buf.len); |
| 335 | |
| 336 | std::cout << "Packet out of length " << buf.len |
| 337 | << " sent through uplink port " << intf_id << std::endl; |
| 338 | |
| 339 | free(buf.val); |
| 340 | |
| 341 | return Status::OK; |
| 342 | } |
| 343 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 344 | Status FlowAdd_(uint32_t onu_id, |
| 345 | uint32_t flow_id, const std::string flow_type, |
| 346 | uint32_t access_intf_id, uint32_t network_intf_id, |
Nicolas Palpacuer | d6cf5aa | 2018-07-16 15:14:39 -0400 | [diff] [blame] | 347 | uint32_t gemport_id, uint32_t priority_value, |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 348 | const ::openolt::Classifier& classifier, |
| 349 | const ::openolt::Action& action) { |
| 350 | bcmos_errno err; |
| 351 | bcmbal_flow_cfg cfg; |
| 352 | bcmbal_flow_key key = { }; |
| 353 | |
| 354 | std::cout << "flow add -" |
| 355 | << " intf_id:" << access_intf_id |
| 356 | << " onu_id:" << onu_id |
| 357 | << " flow_id:" << flow_id |
| 358 | << " flow_type:" << flow_type |
| 359 | << " gemport_id:" << gemport_id |
| 360 | << " network_intf_id:" << network_intf_id |
| 361 | << std::endl; |
| 362 | |
| 363 | key.flow_id = flow_id; |
| 364 | if (flow_type.compare("upstream") == 0 ) { |
| 365 | key.flow_type = BCMBAL_FLOW_TYPE_UPSTREAM; |
| 366 | } else if (flow_type.compare("downstream") == 0) { |
| 367 | key.flow_type = BCMBAL_FLOW_TYPE_DOWNSTREAM; |
| 368 | } else { |
| 369 | std::cout << "Invalid flow type " << flow_type << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 370 | return bcm_to_grpc_err(BCM_ERR_PARM, "Invalid flow type"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | BCMBAL_CFG_INIT(&cfg, flow, key); |
| 374 | |
| 375 | BCMBAL_CFG_PROP_SET(&cfg, flow, admin_state, BCMBAL_STATE_UP); |
| 376 | BCMBAL_CFG_PROP_SET(&cfg, flow, access_int_id, access_intf_id); |
| 377 | BCMBAL_CFG_PROP_SET(&cfg, flow, network_int_id, network_intf_id); |
| 378 | BCMBAL_CFG_PROP_SET(&cfg, flow, sub_term_id, onu_id); |
| 379 | BCMBAL_CFG_PROP_SET(&cfg, flow, svc_port_id, gemport_id); |
Nicolas Palpacuer | d6cf5aa | 2018-07-16 15:14:39 -0400 | [diff] [blame] | 380 | BCMBAL_CFG_PROP_SET(&cfg, flow, priority, priority_value); |
| 381 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 382 | |
| 383 | { |
| 384 | bcmbal_classifier val = { }; |
| 385 | |
| 386 | if (classifier.o_tpid()) { |
| 387 | val.o_tpid = classifier.o_tpid(); |
| 388 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_TPID; |
| 389 | } |
| 390 | |
| 391 | if (classifier.o_vid()) { |
| 392 | val.o_vid = classifier.o_vid(); |
| 393 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_VID; |
| 394 | } |
| 395 | |
| 396 | if (classifier.i_tpid()) { |
| 397 | val.i_tpid = classifier.i_tpid(); |
| 398 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_TPID; |
| 399 | } |
| 400 | |
| 401 | if (classifier.i_vid()) { |
| 402 | val.i_vid = classifier.i_vid(); |
| 403 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_VID; |
| 404 | } |
| 405 | |
| 406 | if (classifier.o_pbits()) { |
| 407 | val.o_pbits = classifier.o_pbits(); |
| 408 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_O_PBITS; |
| 409 | } |
| 410 | |
| 411 | if (classifier.i_pbits()) { |
| 412 | val.i_pbits = classifier.i_pbits(); |
| 413 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_I_PBITS; |
| 414 | } |
| 415 | |
| 416 | if (classifier.eth_type()) { |
| 417 | val.ether_type = classifier.eth_type(); |
| 418 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_ETHER_TYPE; |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | if (classifier.dst_mac()) { |
| 423 | val.dst_mac = classifier.dst_mac(); |
| 424 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_MAC; |
| 425 | } |
| 426 | |
| 427 | if (classifier.src_mac()) { |
| 428 | val.src_mac = classifier.src_mac(); |
| 429 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_MAC; |
| 430 | } |
| 431 | */ |
| 432 | |
| 433 | if (classifier.ip_proto()) { |
| 434 | val.ip_proto = classifier.ip_proto(); |
| 435 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_IP_PROTO; |
| 436 | } |
| 437 | |
| 438 | /* |
| 439 | if (classifier.dst_ip()) { |
| 440 | val.dst_ip = classifier.dst_ip(); |
| 441 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_IP; |
| 442 | } |
| 443 | |
| 444 | if (classifier.src_ip()) { |
| 445 | val.src_ip = classifier.src_ip(); |
| 446 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_IP; |
| 447 | } |
| 448 | */ |
| 449 | |
| 450 | if (classifier.src_port()) { |
| 451 | val.src_port = classifier.src_port(); |
| 452 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_SRC_PORT; |
| 453 | } |
| 454 | |
| 455 | if (classifier.dst_port()) { |
| 456 | val.dst_port = classifier.dst_port(); |
| 457 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_DST_PORT; |
| 458 | } |
| 459 | |
| 460 | if (!classifier.pkt_tag_type().empty()) { |
| 461 | if (classifier.pkt_tag_type().compare("untagged") == 0) { |
| 462 | val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_UNTAGGED; |
| 463 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE; |
| 464 | } else if (classifier.pkt_tag_type().compare("single_tag") == 0) { |
| 465 | val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_SINGLE_TAG; |
| 466 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE; |
| 467 | } else if (classifier.pkt_tag_type().compare("double_tag") == 0) { |
| 468 | val.pkt_tag_type = BCMBAL_PKT_TAG_TYPE_DOUBLE_TAG; |
| 469 | val.presence_mask = val.presence_mask | BCMBAL_CLASSIFIER_ID_PKT_TAG_TYPE; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | BCMBAL_CFG_PROP_SET(&cfg, flow, classifier, val); |
| 474 | } |
| 475 | |
| 476 | { |
| 477 | bcmbal_action val = { }; |
| 478 | |
| 479 | const ::openolt::ActionCmd& cmd = action.cmd(); |
| 480 | |
| 481 | if (cmd.add_outer_tag()) { |
| 482 | val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_ADD_OUTER_TAG; |
| 483 | val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK; |
| 484 | } |
| 485 | |
| 486 | if (cmd.remove_outer_tag()) { |
| 487 | val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_REMOVE_OUTER_TAG; |
| 488 | val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK; |
| 489 | } |
| 490 | |
| 491 | if (cmd.trap_to_host()) { |
| 492 | val.cmds_bitmask |= BCMBAL_ACTION_CMD_ID_TRAP_TO_HOST; |
| 493 | val.presence_mask |= BCMBAL_ACTION_ID_CMDS_BITMASK; |
| 494 | } |
| 495 | |
| 496 | if (action.o_vid()) { |
| 497 | val.o_vid = action.o_vid(); |
| 498 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_VID; |
| 499 | } |
| 500 | |
| 501 | if (action.o_pbits()) { |
| 502 | val.o_pbits = action.o_pbits(); |
| 503 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_PBITS; |
| 504 | } |
| 505 | |
| 506 | if (action.o_tpid()) { |
| 507 | val.o_tpid = action.o_tpid(); |
| 508 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_O_TPID; |
| 509 | } |
| 510 | |
| 511 | if (action.i_vid()) { |
| 512 | val.i_vid = action.i_vid(); |
| 513 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_VID; |
| 514 | } |
| 515 | |
| 516 | if (action.i_pbits()) { |
| 517 | val.i_pbits = action.i_pbits(); |
| 518 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_PBITS; |
| 519 | } |
| 520 | |
| 521 | if (action.i_tpid()) { |
| 522 | val.i_tpid = action.i_tpid(); |
| 523 | val.presence_mask = val.presence_mask | BCMBAL_ACTION_ID_I_TPID; |
| 524 | } |
| 525 | |
| 526 | BCMBAL_CFG_PROP_SET(&cfg, flow, action, val); |
| 527 | } |
| 528 | |
| 529 | { |
| 530 | bcmbal_tm_sched_id val; |
| 531 | val = (bcmbal_tm_sched_id) mk_sched_id(onu_id); |
| 532 | BCMBAL_CFG_PROP_SET(&cfg, flow, dba_tm_sched_id, val); |
| 533 | } |
| 534 | |
Shad Ansari | 0610195 | 2018-07-25 00:22:09 +0000 | [diff] [blame^] | 535 | if (key.flow_type == BCMBAL_FLOW_TYPE_DOWNSTREAM) { |
| 536 | bcmbal_tm_queue_ref val = { }; |
| 537 | val.sched_id = access_intf_id << 7 | onu_id; |
| 538 | val.queue_id = 0; |
| 539 | BCMBAL_CFG_PROP_SET(&cfg, flow, queue, val); |
| 540 | } |
| 541 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 542 | err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr)); |
| 543 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 544 | std::cout << "ERROR: flow add failed" << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 545 | return bcm_to_grpc_err(err, "flow add failed"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 548 | register_new_flow(key); |
| 549 | |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 550 | return Status::OK; |
| 551 | } |
| 552 | |
| 553 | Status SchedAdd_(int intf_id, int onu_id, int agg_port_id) { |
| 554 | bcmbal_tm_sched_cfg cfg; |
| 555 | bcmbal_tm_sched_key key = { }; |
| 556 | bcmbal_tm_sched_type sched_type; |
| 557 | |
| 558 | key.id = mk_sched_id(onu_id); |
| 559 | key.dir = BCMBAL_TM_SCHED_DIR_US; |
| 560 | |
| 561 | BCMBAL_CFG_INIT(&cfg, tm_sched, key); |
| 562 | |
| 563 | { |
| 564 | bcmbal_tm_sched_owner val = { }; |
| 565 | |
| 566 | val.type = BCMBAL_TM_SCHED_OWNER_TYPE_AGG_PORT; |
| 567 | val.u.agg_port.intf_id = (bcmbal_intf_id) intf_id; |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 568 | val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_INTF_ID; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 569 | val.u.agg_port.sub_term_id = (bcmbal_sub_id) onu_id; |
| 570 | val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_SUB_TERM_ID; |
Nicolas Palpacuer | 0f19b1a | 2018-06-07 17:29:31 -0400 | [diff] [blame] | 571 | val.u.agg_port.agg_port_id = (bcmbal_aggregation_port_id) agg_port_id; |
| 572 | val.u.agg_port.presence_mask = val.u.agg_port.presence_mask | BCMBAL_TM_SCHED_OWNER_AGG_PORT_ID_AGG_PORT_ID; |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 573 | |
| 574 | BCMBAL_CFG_PROP_SET(&cfg, tm_sched, owner, val); |
| 575 | } |
| 576 | |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 577 | bcmos_errno err = bcmbal_cfg_set(DEFAULT_ATERM_ID, &(cfg.hdr)); |
| 578 | if (err) { |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 579 | std::cout << "ERROR: Failed to create upstream DBA sched" |
| 580 | << " id:" << key.id |
| 581 | << " intf_id:" << intf_id |
| 582 | << " onu_id:" << onu_id << std::endl; |
Nicolas Palpacuer | 73222e0 | 2018-07-16 12:20:26 -0400 | [diff] [blame] | 583 | return bcm_to_grpc_err(err, "Failed to create upstream DBA sched"); |
Shad Ansari | b7b0ced | 2018-05-11 21:53:32 +0000 | [diff] [blame] | 584 | //return 1; |
| 585 | } |
| 586 | std::cout << "create upstream DBA sched" |
| 587 | << " id:" << key.id |
| 588 | << " intf_id:" << intf_id |
| 589 | << " onu_id:" << onu_id << std::endl; |
| 590 | |
| 591 | return Status::OK; |
| 592 | //return 0; |
| 593 | } |
Jonathan Davis | 70c2181 | 2018-07-19 15:32:10 -0400 | [diff] [blame] | 594 | |
| 595 | Status SchedRemove_(int intf_id, int onu_id, int agg_port_id) { |
| 596 | bcmbal_tm_sched_cfg cfg; |
| 597 | bcmbal_tm_sched_key key = { }; |
| 598 | bcmbal_tm_sched_type sched_type; |
| 599 | |
| 600 | key.id = mk_sched_id(onu_id); |
| 601 | key.dir = BCMBAL_TM_SCHED_DIR_US; |
| 602 | |
| 603 | BCMBAL_CFG_INIT(&cfg, tm_sched, key); |
| 604 | |
| 605 | if (bcmbal_cfg_clear(DEFAULT_ATERM_ID, &(cfg.hdr))) { |
| 606 | std::cout << "ERROR: Failed to remove upstream DBA sched" |
| 607 | << " id:" << key.id |
| 608 | << " intf_id:" << intf_id |
| 609 | << " onu_id:" << onu_id << std::endl; |
| 610 | return Status(grpc::StatusCode::INTERNAL, "Failed to remove upstream DBA sched"); |
| 611 | } |
| 612 | |
| 613 | std::cout << "remove upstream DBA sched" |
| 614 | << " id:" << key.id |
| 615 | << " intf_id:" << intf_id |
| 616 | << " onu_id:" << onu_id << std::endl; |
| 617 | |
| 618 | return Status::OK; |
| 619 | //return 0; |
| 620 | } |