Skip to content
Snippets Groups Projects
qos_bbf.c 84.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    /*
     * Copyright (C) 2021 iopsys Software Solutions AB
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU Lesser General Public License version 2.1
     * as published by the Free Software Foundation
     *
     *	Author: Omar Kallel <omar.kallel@pivasoftware.com>
     *	Author: Rohit Topno <r.topno@gxgroup.eu>
     */
    
    #include "qos_bbf.h"
    
    /*************************************************************
    * COMMON FUNCTIONS
    **************************************************************/
    static unsigned long qos_get_new_order(void)
    {
    	struct uci_section *s = NULL;
    	char *order = NULL;
    	unsigned long max = 0;
    
    	uci_foreach_sections("qos", "classify", s) {
    		dmuci_get_value_by_section_string(s, "order", &order);
    		unsigned long order_tol = DM_STRTOL(order);
    		if (order_tol > max)
    			max = order_tol;
    	}
    
    	return max + 1;
    }
    
    static bool qos_is_order_exists(const char *order)
    {
    	struct uci_section *s = NULL;
    	char *curr_order = NULL;
    
    	uci_foreach_sections("qos", "classify", s) {
    		dmuci_get_value_by_section_string(s, "order", &curr_order);
    		if (DM_STRCMP(curr_order, order) == 0)
    			return true;
    	}
    
    	return false;
    }
    
    static void qos_update_order(const char *order, bool is_del)
    {
    	struct uci_section *classify_s = NULL;
    	char *curr_order = NULL;
    	unsigned long order_tol = DM_STRTOL(order);
    
    	uci_foreach_sections("qos", "classify", classify_s) {
    		dmuci_get_value_by_section_string(classify_s, "order", &curr_order);
    		unsigned long curr_order_tol = DM_STRTOL(curr_order);
    		if (curr_order_tol >= order_tol) {
    			char new_order[16] = {0};
    
    			unsigned long order_ul = is_del ? curr_order_tol - 1 : curr_order_tol + 1;
    			DM_ULTOSTR(new_order, order_ul, sizeof(new_order));
    
    			dmuci_set_value_by_section(classify_s, "order", new_order);
    		}
    	}
    }
    
    /*************************************************************
     * ENTRY METHOD
    *************************************************************/
    static int browseQoSClassificationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
    {
    	struct dm_data *curr_data = NULL;
    	LIST_HEAD(dup_list);
    	char *inst = NULL;
    
    	synchronize_specific_config_sections_with_dmmap("qos", "classify", "dmmap_qos", &dup_list);
    	list_for_each_entry(curr_data, &dup_list, list) {
    
    		inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "classify_instance", "classify_alias");
    
    		if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP)
    			break;
    	}
    	free_dmmap_config_dup_list(&dup_list);
    	return 0;
    }
    
    static int browseQoSPolicerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
    {
    	struct dm_data *curr_data = NULL;
    	LIST_HEAD(dup_list);
    	char *inst = NULL;
    
    	synchronize_specific_config_sections_with_dmmap("qos", "policer", "dmmap_qos", &dup_list);
    	list_for_each_entry(curr_data, &dup_list, list) {
    
    		inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "policer_instance", "policeralias");
    
    		if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP)
    			break;
    	}
    	free_dmmap_config_dup_list(&dup_list);
    	return 0;
    }
    
    /*#Device.QoS.Queue.{i}.!UCI:qos/queue/dmmap_qos*/
    static int browseQoSQueueInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
    {
    	struct dm_data *curr_data = NULL;
    	LIST_HEAD(dup_list);
    	char *inst = NULL;
    
    	synchronize_specific_config_sections_with_dmmap("qos", "queue", "dmmap_qos", &dup_list);
    	list_for_each_entry(curr_data, &dup_list, list) {
    
    		dmuci_set_value_by_section(curr_data->dmmap_section, "queuealias", section_name(curr_data->config_section));
    
    		inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "queueinstance", "queuealias");
    
    		if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP)
    			break;
    	}
    	free_dmmap_config_dup_list(&dup_list);
    	return 0;
    }
    
    static int browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
    {
    	struct uci_section *s = NULL;
    	char *inst = NULL;
    
    	uci_path_foreach_sections(bbfdm, "dmmap_qstats", "queue_stats", s) {
    
    		inst = handle_instance(dmctx, parent_node, s, "q_instance", "q_alias");
    
    		if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
    			break;
    	}
    	return 0;
    }
    
    static int browseQoSShaperInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
    {
    	struct dm_data *curr_data = NULL;
    	LIST_HEAD(dup_list);
    	char *inst = NULL;
    
    	synchronize_specific_config_sections_with_dmmap("qos", "shaper", "dmmap_qos", &dup_list);
    	list_for_each_entry(curr_data, &dup_list, list) {
    
    		inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "shaperinstance", "shaperalias");
    
    		if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP)
    			break;
    	}
    	free_dmmap_config_dup_list(&dup_list);
    	return 0;
    }
    
    /*************************************************************
     * ADD & DEL OBJ
    *************************************************************/
    static int addObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char **instance)
    {
    	struct uci_section *classify_s = NULL, *dmmap_s = NULL;
    	char order_str[32] = {0};
    	char buf[32] = {0};
    
    	unsigned long order_ul = qos_get_new_order();
    	DM_ULTOSTR(order_str, order_ul, sizeof(order_str));
    
    	snprintf(buf, sizeof(buf), "classify_%s", *instance);
    
    	dmuci_add_section("qos", "classify", &classify_s);
    	dmuci_rename_section_by_section(classify_s, buf);
    	dmuci_set_value_by_section(classify_s, "enable", "0");
    	dmuci_set_value_by_section(classify_s, "order", order_str);
    
    	dmuci_add_section_bbfdm("dmmap_qos", "classify", &dmmap_s);
    	dmuci_set_value_by_section(dmmap_s, "section_name", buf);
    	dmuci_set_value_by_section(dmmap_s, "classify_instance", *instance);
    	return 0;
    }
    
    static int delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
    {
    	struct uci_section *s = NULL, *stmp = NULL;
    	char *curr_order = NULL;
    
    	switch (del_action) {
    	case DEL_INST:
    		dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "order", &curr_order);
    		qos_update_order(curr_order, true);
    
    		dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL);
    		dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL);
    		break;
    	case DEL_ALL:
    		uci_foreach_sections_safe("qos", "classify", stmp, s) {
    			struct uci_section *dmmap_qos = NULL;
    
    			get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(s), &dmmap_qos);
    			dmuci_delete_by_section(dmmap_qos, NULL, NULL);
    
    			dmuci_delete_by_section(s, NULL, NULL);
    		}
    		break;
    	}
    	return 0;
    }
    
    static int addObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char **instance)
    {
    	struct uci_section *dmmap = NULL, *s = NULL;
    
    	dmuci_add_section("qos", "policer", &s);
    	dmuci_set_value_by_section(s, "enable", "0");
    	dmuci_set_value_by_section(s, "committed_rate", "0");
    	dmuci_set_value_by_section(s, "committed_burst_size", "0");
    	dmuci_set_value_by_section(s, "excess_burst_size", "0");
    	dmuci_set_value_by_section(s, "peak_rate", "0");
    	dmuci_set_value_by_section(s, "peak_burst_size", "0");
    	dmuci_set_value_by_section(s, "meter_type", "0");
    	dmuci_set_value_by_section(s, "name", section_name(s));
    
    	dmuci_add_section_bbfdm("dmmap_qos", "policer", &dmmap);
    	dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
    	dmuci_set_value_by_section(dmmap, "policer_instance", *instance);
    	return 0;
    }
    
    static int delObjQoSPolicer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
    {
    	struct uci_section *s = NULL, *stmp = NULL, *sec = NULL;
    	char *p_name = NULL;
    
    	switch (del_action) {
    		case DEL_INST:
    			// store section name to update corresponding classification
    			// section if any
    			dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "name", &p_name);
    
    			// Set the Classification.Policer to blank if corresponding
    			// Policer instance has been deleted
    			uci_foreach_option_eq("qos", "classify", "policer", p_name, sec) {
    				dmuci_set_value_by_section(sec, "policer", "");
    			}
    
    			dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL);
    			dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL);
    			break;
    		case DEL_ALL:
    			uci_foreach_sections_safe("qos", "policer", stmp, s) {
    				struct uci_section *dmmap_section = NULL;
    
    				get_dmmap_section_of_config_section("dmmap_qos", "policer", section_name(s), &dmmap_section);
    				dmuci_delete_by_section(dmmap_section, NULL, NULL);
    
    				dmuci_delete_by_section(s, NULL, NULL);
    			}
    
    			// Since all policer have been deleted, we can safely set the
    			// value of all Classification.Policer params to empty
    			uci_foreach_sections("qos", "classify", sec) {
    				dmuci_set_value_by_section(sec, "policer", "");
    			}
    			break;
    	}
    	return 0;
    }
    
    static int addObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char **instance)
    {
    	struct uci_section  *dmmap = NULL, *s = NULL;
    
    	dmuci_add_section("qos", "queue", &s);
    	dmuci_set_value_by_section(s, "enable", "false");
    	dmuci_set_value_by_section(s, "weight", "0");
    	dmuci_set_value_by_section(s, "precedence", "1");
    	dmuci_set_value_by_section(s, "burst_size", "0");
    	dmuci_set_value_by_section(s, "scheduling", "SP");
    	dmuci_set_value_by_section(s, "rate", "-1");
    
    	dmuci_add_section_bbfdm("dmmap_qos", "queue", &dmmap);
    	dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
    	dmuci_set_value_by_section(dmmap, "queueinstance", *instance);
    	return 0;
    }
    
    static int delObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
    {
    	struct uci_section *s = NULL, *stmp = NULL;
    
    	switch (del_action) {
    		case DEL_INST:
    			dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL);
    			dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL);
    			break;
    		case DEL_ALL:
    			uci_foreach_sections_safe("qos", "queue", stmp, s) {
    				struct uci_section *dmmap_section = NULL;
    
    				get_dmmap_section_of_config_section("dmmap_qos", "queue", section_name(s), &dmmap_section);
    				dmuci_delete_by_section(dmmap_section, NULL, NULL);
    
    				dmuci_delete_by_section(s, NULL, NULL);
    			}
    			break;
    	}
    	return 0;
    }
    
    static int addObjQoSQueueStats(char *refparam, struct dmctx *ctx, void *data, char **instance)
    {
    	struct uci_section *qstats_sec = NULL;
    
    	dmuci_add_section_bbfdm("dmmap_qstats", "queue_stats", &qstats_sec);
    	dmuci_set_value_by_section(qstats_sec, "q_instance", *instance);
    	return 0;
    }
    
    static int delObjQoSQueueStats(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
    {
    	struct uci_section *s = NULL, *stmp = NULL;
    
    	switch (del_action) {
    		case DEL_INST:
    			dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
    			break;
    		case DEL_ALL:
    			uci_path_foreach_sections_safe(bbfdm, "dmmap_qstats", "queue_stats", stmp, s) {
    				dmuci_delete_by_section(s, NULL, NULL);
    			}
    			break;
    	}
    	return 0;
    }
    
    static int addObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char **instance)
    {
    	struct uci_section  *dmmap = NULL, *s = NULL;
    
    	dmuci_add_section("qos", "shaper", &s);
    	dmuci_set_value_by_section(s, "enable", "0");
    	dmuci_set_value_by_section(s, "burst_size", "0");
    	dmuci_set_value_by_section(s, "rate", "0");
    
    	dmuci_add_section_bbfdm("dmmap_qos", "shaper", &dmmap);
    	dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
    	dmuci_set_value_by_section(dmmap, "shaperinstance", *instance);
    	return 0;
    }
    
    static int delObjQoSShaper(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
    {
    	struct uci_section *s = NULL, *stmp = NULL;
    
    	switch (del_action) {
    		case DEL_INST:
    			dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL);
    			dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL);
    			break;
    		case DEL_ALL:
    			uci_foreach_sections_safe("qos", "shaper", stmp, s) {
    				struct uci_section *dmmap_section = NULL;
    
    				get_dmmap_section_of_config_section("dmmap_qos", "shaper", section_name(s), &dmmap_section);
    				dmuci_delete_by_section(dmmap_section, NULL, NULL);
    
    				dmuci_delete_by_section(s, NULL, NULL);
    			}
    			break;
    	}
    	return 0;
    }
    
    /*************************************************************
    * COMMON Functions
    **************************************************************/
    static int get_QInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	char *linker = NULL;
    
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "ifname", &linker);
    
    	adm_entry_get_reference_param(ctx, "Device.IP.Interface.*.Name", linker, value);
    
    	if (!DM_STRLEN(*value))
    		adm_entry_get_reference_param(ctx, "Device.PPP.Interface.*.Name", linker, value);
    
    	if (!DM_STRLEN(*value))
    		adm_entry_get_reference_param(ctx, "Device.Ethernet.Interface.*.Name", linker, value);
    
    	if (!DM_STRLEN(*value))
    		adm_entry_get_reference_param(ctx, "Device.WiFi.Radio.*.Name", linker, value);
    
    	return 0;
    }
    
    static int set_QInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	char *allowed_objects[] = {
    			"Device.IP.Interface.",
    			"Device.PPP.Interface.",
    			"Device.Ethernet.Interface.",
    			"Device.WiFi.Radio.",
    			NULL};
    	struct dm_reference reference = {0};
    
    	bbf_get_reference_args(value, &reference);
    
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_string(ctx, reference.path, -1, 256, NULL, NULL))
    			return FAULT_9007;
    
    		if (dm_validate_allowed_objects(ctx, &reference, allowed_objects))
    			return FAULT_9007;
    
    		break;
    	case VALUESET:
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "ifname", reference.value);
    		break;
    	}
    	return 0;
    }
    
    /*************************************************************
     * GET & SET PARAM
    *************************************************************/
    /*#Device.QoS.ClassificationNumberOfEntries!UCI:qos/classify/*/
    static int get_QClassificationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	int cnt = get_number_of_entries(ctx, data, instance, browseQoSClassificationInst);
    	dmasprintf(value, "%d", cnt);
    	return 0;
    }
    
    static int get_QPolicerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	int cnt = get_number_of_entries(ctx, data, instance, browseQoSPolicerInst);
    	dmasprintf(value, "%d", cnt);
    	return 0;
    }
    
    static int get_QMaxQueueEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = "100";
    	return 0;
    }
    
    /*#Device.QoS.QueueNumberOfEntries!UCI:qos/queue*/
    static int get_QQueueNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	int cnt = get_number_of_entries(ctx, data, instance, browseQoSQueueInst);
    	dmasprintf(value, "%d", cnt);
    	return 0;
    }
    
    static int get_QMaxClassificationEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = "50";
    	return 0;
    }
    
    static int get_QMaxAppEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = "0";
    	return 0;
    }
    
    static int get_QAppNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = "0";
    	return 0;
    }
    
    static int get_QMaxFlowEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = "0";
    	return 0;
    }
    
    static int get_QFlowNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = "0";
    	return 0;
    }
    
    static int get_QMaxPolicerEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = "50";
    	return 0;
    }
    
    static int get_QQueueStatsNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	int cnt = get_number_of_entries(ctx, data, instance, browseQoSQueueStatsInst);
    	dmasprintf(value, "%d", cnt);
    	return 0;
    }
    
    static int get_QShaperNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	int cnt = get_number_of_entries(ctx, data, instance, browseQoSShaperInst);
    	dmasprintf(value, "%d", cnt);
    	return 0;
    }
    
    static int get_QAvailableAppList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = "";
    	return 0;
    }
    
    static int get_QoSClassification_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "enable", "1");
    	return 0;
    }
    
    static int set_QoSClassification_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	bool b;
    
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_boolean(ctx, value))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		string_to_bool(value, &b);
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "enable", (b) ? "1" : "0");
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "order", value);
    	return 0;
    }
    
    static int set_QoSClassification_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	char *curr_order = NULL;
    
    	switch (action)	{
    		case VALUECHECK:
    			if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{NULL,NULL}}, 1))
    				return FAULT_9007;
    			break;
    		case VALUESET:
    			dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "order", &curr_order);
    			if (qos_is_order_exists(value))
    				qos_update_order(value, false);
    
    			dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "order", value);
    			break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_DestMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	char *dest_ip = NULL;
    	char *mask = NULL;
    
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "dest_ip", &dest_ip);
    	// dest_ip can be of type, 'x.x.x.x' or 'x.x.x.x/y'
    	if (DM_STRLEN(dest_ip))
    		mask = strchr(dest_ip, '/');
    
    	*value = mask ? mask : "";
    	return 0;
    }
    
    static int set_QoSClassification_DestMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	char dest_ip[32] = {0};
    	char *ip = NULL, *ip_addr = NULL, *mask = NULL;
    
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_string(ctx, value, -1, 49 , NULL, IPPrefix))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		/* Destination IP address mask is represented as an IP routing prefix using CIDR notation. The IP address part MUST be an empty
    		 * string (and, if specified, MUST be ignored). Possible values are 'x.x.x.x/y' or '/y' and in case of 'x.x.x.x/y' ip address
    		 * part is ignored.
    		 */
    
    		ip_addr = strtok(value, "/");
    		if (ip_addr) {
    			mask = strtok(NULL, "/");
    			if (mask == NULL)
    				mask = ip_addr;
    		}
    
    		// get destination ip addr from qos classify uci section
    		dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "dest_ip", &ip);
    
    		ip_addr = strtok(ip, "/");
    
    		snprintf(dest_ip, sizeof(dest_ip), "%s/%s", ip_addr ? ip_addr : "0.0.0.0", mask);
    
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "dest_ip", dest_ip);
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_SourceMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	char *src_ip = NULL;
    	char *mask = NULL;
    
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "src_ip", &src_ip);
    	// src_ip can be of type, 'x.x.x.x' or 'x.x.x.x/y'
    	if (DM_STRLEN(src_ip))
    		mask = strchr(src_ip, '/');
    
    	*value = mask ? mask : "";
    	return 0;
    }
    
    static int set_QoSClassification_SourceMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	char dest_ip[32] = {0};
    	char *ip = NULL, *ip_addr = NULL, *mask = NULL;
    
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_string(ctx, value, -1, 49 , NULL, IPPrefix))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		/* Source IP address mask is represented as an IP routing prefix using CIDR notation. The IP address part MUST be an empty
    		 * string (and, if specified, MUST be ignored). Possible values are 'x.x.x.x/y' or '/y' and in case of 'x.x.x.x/y' ip address
    		 * part is ignored.
    		 */
    
    		ip_addr = strtok(value, "/");
    		if (ip_addr) {
    			mask = strtok(NULL, "/");
    			if (mask == NULL)
    				mask = ip_addr;
    		}
    
    		// get source ip addr from qos classify uci section
    		dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "src_ip", &ip);
    
    		ip_addr = strtok(ip, "/");
    
    		snprintf(dest_ip, sizeof(dest_ip), "%s/%s", ip_addr ? ip_addr : "0.0.0.0", mask);
    
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "src_ip", dest_ip);
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "classify_alias", instance, value);
    }
    
    static int set_QoSClassification_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "classify_alias", instance, value);
    }
    
    static int get_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	return get_QInterface(refparam, ctx, data, instance, value);
    }
    
    static int set_QoSClassification_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	return set_QInterface(refparam, ctx, data, instance, value, action);
    }
    
    static int get_QoSClassification_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "all_interfaces", "0");
    	return 0;
    }
    
    static int set_QoSClassification_AllInterfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	bool b;
    
    	switch (action) {
    	case VALUECHECK:
    		if (bbfdm_validate_boolean(ctx, value))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		string_to_bool(value, &b);
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "all_interfaces", (b) ? "1" : "0");
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_DestIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	char *dest_ip = NULL;
    
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "dest_ip", &dest_ip);
    	if (DM_STRLEN(dest_ip)) {
    		char *mask = strchr(dest_ip, '/');
    		if (mask)
    			*mask = 0;
    	}
    
    	*value = dest_ip;
    	return 0;
    }
    
    static int set_QoSClassification_DestIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	char *dest_mask = NULL, *ip = NULL;
    
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_string(ctx, value, -1, 45 , NULL, IPAddress))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		/* First, get the existing destination ip addr from qos classify uci section, if present.
    		 * IP addr can be of type, 'x.x.x.x' or 'x.x.x.x/y'
    		 * If IP addr is of type 'x.x.x.x/y' then get its mask(y) and use with the new dest IP.
    		 */
    		dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "dest_ip", &ip);
    
    		if (ip[0] != '\0') {
    			strtok(ip, "/");
    			dest_mask = strtok(NULL, "/");
    		}
    
    		if (dest_mask != NULL) {
    			char dest_ip[64] = {0};
    
    			snprintf(dest_ip, sizeof(dest_ip), "%s/%s", value, dest_mask);
    			dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "dest_ip", dest_ip);
    		} else {
    			dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "dest_ip", value);
    		}
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_SourceIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	char *src_ip = NULL;
    
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "src_ip", &src_ip);
    	if (DM_STRLEN(src_ip)) {
    		char *mask = strchr(src_ip, '/');
    		if (mask)
    			*mask = 0;
    	}
    
    	*value = src_ip;
    	return 0;
    }
    
    static int set_QoSClassification_SourceIP(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	char *src_mask = NULL, *mask = NULL;
    
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_string(ctx, value, -1, 45 , NULL, IPAddress))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		/* First, get the existing source ip addr from qos classify uci section, if present.
    		 * IP addr can be of type, 'x.x.x.x' or 'x.x.x.x/y'
    		 * If IP addr is of type 'x.x.x.x/y' then get its mask(y) and use with the new source IP.
    		 */
    		dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "src_ip", &src_mask);
    
    		if (src_mask[0] != '\0') {
    			strtok(src_mask, "/");
    			mask = strtok(NULL, "/");
    		}
    
    		if (mask != NULL) {
    			char src_ip[64] = {0};
    
    			snprintf(src_ip, sizeof(src_ip), "%s/%s", value, mask);
    			dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "src_ip", src_ip);
    		} else {
    			dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "src_ip", value);
    		}
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "proto", "-1");
    	return 0;
    }
    
    static int set_QoSClassification_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_int(ctx, value, RANGE_ARGS{{"-1","255"}}, 1))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "proto", value);
    		break;
    	}
    	return 0;
    }
    
    
    static int get_QoSClassification_DestPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "dest_port", "-1");
    	return 0;
    }
    
    static int set_QoSClassification_DestPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_int(ctx, value, RANGE_ARGS{{"-1","65535"}}, 1))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "dest_port", value);
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_DestPortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "dest_port_range", "-1");
    	return 0;
    }
    
    static int set_QoSClassification_DestPortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    		case VALUECHECK:
    			if (bbfdm_validate_int(ctx, value, RANGE_ARGS{{"-1","65535"}}, 1))
    				return FAULT_9007;
    			break;
    		case VALUESET:
    			dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "dest_port_range", value);
    			break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_SourcePort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "src_port", "-1");
    	return 0;
    }
    
    static int set_QoSClassification_SourcePort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    		case VALUECHECK:
    			if (bbfdm_validate_int(ctx, value, RANGE_ARGS{{"-1","65535"}}, 1))
    				return FAULT_9007;
    			break;
    		case VALUESET:
    			dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "src_port", value);
    			break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_SourcePortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "src_port_range", "-1");
    	return 0;
    }
    
    static int set_QoSClassification_SourcePortRangeMax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_int(ctx, value, RANGE_ARGS{{"-1","65535"}}, 1))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "src_port_range", value);
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_SourceMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "src_mac", value);
    	return 0;
    }
    
    static int set_QoSClassification_SourceMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_string(ctx, value, -1, 17, NULL, MACAddress))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "src_mac", value);
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_DestMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "dst_mac", value);
    	return 0;
    }
    
    static int set_QoSClassification_DestMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_string(ctx, value, -1, 17, NULL, MACAddress))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "dst_mac", value);
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_Ethertype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "ethertype", "-1");
    	return 0;
    }
    
    static int set_QoSClassification_Ethertype(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_int(ctx, value, RANGE_ARGS{{"-1",NULL}}, 1))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "ethertype", value);
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_SourceVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "src_vendor_class_id", value);
    	return 0;
    }
    
    static int set_QoSClassification_SourceVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_string(ctx, value, -1, 255, NULL, NULL))
    			return FAULT_9007;
    		break;
    	case VALUESET:
    		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "src_vendor_class_id", value);
    		break;
    	}
    	return 0;
    }
    
    static int get_QoSClassification_DestVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
    {
    	dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "dst_vendor_class_id", value);
    	return 0;
    }
    
    static int set_QoSClassification_DestVendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
    {
    	switch (action)	{
    	case VALUECHECK:
    		if (bbfdm_validate_string(ctx, value, -1, 255, NULL, NULL))
    			return FAULT_9007;
    		break;
    	case VALUESET: