libbbf: moved DSL,FAST,ATM,PTM as microservice

This commit is contained in:
Amit Kumar 2024-03-13 13:51:30 +00:00 committed by Vivek Kumar Dutta
parent db6d7395f4
commit e7780c2b24
11 changed files with 14 additions and 3535 deletions

View file

@ -98,3 +98,7 @@ All supported tools are presented in this file[BBFDM Tools](./tools/README.md)
| Device.DynamicDNS. | ddnsmngr | https://dev.iopsys.eu/bbf/ddnsmngr.git |
| Device.Hosts. | hostmngr | https://dev.iopsys.eu/iopsys/hostmngr.git |
| Device.Services.VoiceService. | tr104 | https://dev.iopsys.eu/voice/tr104.git |
| Device.DSL. | dslmngr | https://dev.iopsys.eu/hal/dslmngr.git |
| Device.FAST. | dslmngr | https://dev.iopsys.eu/hal/dslmngr.git |
| Device.ATM. | dslmngr | https://dev.iopsys.eu/hal/dslmngr.git |
| Device.PTM. | dslmngr | https://dev.iopsys.eu/hal/dslmngr.git |

View file

@ -1,420 +0,0 @@
/*
* Copyright (C) 2019 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: Anis Ellouze <anis.ellouze@pivasoftware.com>
*
*/
#include "atm.h"
struct atm_args
{
struct dmmap_dup *sections;
char *device;
};
/**************************************************************************
* INIT
***************************************************************************/
static inline int init_atm_link(struct atm_args *args, struct dmmap_dup *s, char *device)
{
args->sections = s;
args->device = device;
return 0;
}
/*************************************************************
* COMMON FUNCTIONS
**************************************************************/
void remove_device_from_interface(struct uci_section *interface_s, char *device)
{
char *curr_device = NULL;
char new_device[64] = {0};
unsigned pos = 0;
if (!interface_s || !device)
return;
dmuci_get_value_by_section_string(interface_s, "device", &curr_device);
if (DM_STRLEN(curr_device) == 0)
return;
new_device[0] = '\0';
char *pch = NULL, *spch = NULL;
for (pch = strtok_r(curr_device, " ", &spch); pch; pch = strtok_r(NULL, " ", &spch)) {
if (strcmp(pch, device) == 0)
continue;
pos += snprintf(&new_device[pos], sizeof(new_device) - pos, "%s ", pch);
}
if (pos)
new_device[pos - 1] = 0;
dmuci_set_value_by_section(interface_s, "device", new_device);
}
/*************************************************************
* ENTRY METHOD
*************************************************************/
/*#Device.ATM.Link.{i}.!UCI:dsl/atm-device/dmmap_dsl*/
static int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *device;
struct atm_args curr_atm_args = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dsl", "atm-device", "dmmap_dsl", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "device", &device);
init_atm_link(&curr_atm_args, p, device);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "atmlinkinstance", "atmlinkalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_atm_args, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*************************************************************
* ADD & DEL OBJ
**************************************************************/
static int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_atm = NULL;
char atm_device[16];
snprintf(atm_device, sizeof(atm_device), "atm%s", *instance);
dmuci_set_value("dsl", atm_device, "", "atm-device");
dmuci_set_value("dsl", atm_device, "name", "ATM");
dmuci_set_value("dsl", atm_device, "enabled", "0");
dmuci_set_value("dsl", atm_device, "vpi", "8");
dmuci_set_value("dsl", atm_device, "vci", "35");
dmuci_set_value("dsl", atm_device, "device", atm_device);
dmuci_add_section_bbfdm("dmmap_dsl", "atm-device", &dmmap_atm);
dmuci_set_value_by_section(dmmap_atm, "section_name", atm_device);
dmuci_set_value_by_section(dmmap_atm, "atmlinkinstance", *instance);
return 0;
}
static int delete_atm_link(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:
uci_foreach_option_cont("network", "interface", "device", ((struct atm_args *)data)->device, s) {
remove_device_from_interface(stmp, ((struct atm_args *)data)->device);
}
dmuci_delete_by_section((((struct atm_args *)data)->sections)->dmmap_section, NULL, NULL);
dmuci_delete_by_section((((struct atm_args *)data)->sections)->config_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("dsl", "atm-device", stmp, s) {
struct uci_section *ns = NULL;
char *device = NULL;
dmuci_get_value_by_section_string(s, "device", &device);
if (DM_STRLEN(device) == 0)
continue;
uci_foreach_option_cont("network", "interface", "device", device, ns) {
remove_device_from_interface(ns, device);
}
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(s), &ns);
dmuci_delete_by_section(ns, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
/*#Device.ATM.Link.{i}.DestinationAddress!UCI:dsl/atm-device,@i-1/vpi&UCI:dsl/atm-device,@i-1/vci*/
static int get_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *vpi, *vci;
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "vpi", &vpi);
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "vci", &vci);
dmasprintf(value, "%s/%s", vpi, vci); // MEM WILL BE FREED IN DMMEMCLEAN
return 0;
}
static int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *Destination_Address[] = {"^\\d+/\\d+$", NULL};
char *vpi = NULL, *vci = NULL, *spch;
switch (action) {
case VALUECHECK:
if (bbfdm_validate_string(ctx, value, -1, 256, NULL, Destination_Address))
return FAULT_9007;
return 0;
case VALUESET:
vpi = strtok_r(value, "/", &spch);
if (vpi)
vci = strtok_r(NULL, "/", &spch);
if (vpi && vci) {
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "vpi", vpi);
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "vci", vci);
}
return 0;
}
return 0;
}
/*#Device.ATM.Link.{i}.Name!UCI:dsl/atm-device,@i-1/name*/
static int get_atm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmstrdup(((struct atm_args *)data)->device);
return 0;
}
/*#Device.ATM.Link.{i}.Encapsulation!UCI:dsl/atm-device,@i-1/encapsulation*/
static int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *encapsulation;
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "encapsulation", &encapsulation);
*value = (DM_LSTRCMP(encapsulation, "vcmux") == 0) ? "VCMUX" : "LLC";
return 0;
}
static int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *encapsulation[] = {"LLC", "VCMUX", NULL};
switch (action) {
case VALUECHECK:
if (bbfdm_validate_string(ctx, value, -1, -1, encapsulation, NULL))
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "encapsulation", (DM_LSTRCMP(value, "LLC") == 0) ? "llc" : "vcmux");
return 0;
}
return 0;
}
/*#Device.ATM.Link.{i}.LinkType!UCI:dsl/atm-device,@i-1/link_type*/
static int get_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *link_type;
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "link_type", &link_type);
if (DM_LSTRCMP(link_type, "eoa") == 0)
*value = "EoA";
else if (DM_LSTRCMP(link_type, "ipoa") == 0)
*value = "IPoA";
else if (DM_LSTRCMP(link_type, "pppoa") == 0)
*value = "PPPoA";
else if (DM_LSTRCMP(link_type, "cip") == 0)
*value = "CIP";
else
*value = "Unconfigured";
return 0;
}
static int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *Link_Type[] = {"EoA", "IPoA", "PPPoA", "CIP", "Unconfigured", NULL};
switch (action) {
case VALUECHECK:
if (bbfdm_validate_string(ctx, value, -1, -1, Link_Type, NULL))
return FAULT_9007;
return 0;
case VALUESET:
if (DM_LSTRCMP(value, "EoA") == 0)
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "eoa");
else if (DM_LSTRCMP(value, "IPoA") == 0)
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "ipoa");
else if (DM_LSTRCMP(value, "PPPoA") == 0)
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "pppoa");
else if (DM_LSTRCMP(value, "CIP") == 0)
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "cip");
else
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "");
return 0;
}
return 0;
}
static int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->dmmap_section, "LowerLayers", value);
if ((*value)[0] == '\0') {
char atm_file[128];
snprintf(atm_file, sizeof(atm_file), "/sys/class/net/atm%ld", DM_STRTOL(instance) - 1);
if (folder_exists(atm_file))
adm_entry_get_reference_param(ctx, "Device.DSL.Channel.*.Name", instance, value);
// Store LowerLayers value
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->dmmap_section, "LowerLayers", *value);
} else {
if (!adm_entry_object_exists(ctx, *value))
*value = "";
}
return 0;
}
static int set_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct dm_reference reference = {0};
bbf_get_reference_args(value, &reference);
switch (action) {
case VALUECHECK:
if (DM_LSTRNCMP(reference.path, "Device.DSL.Channel.1", strlen("Device.DSL.Channel.1")) != 0)
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->dmmap_section, "LowerLayers", reference.path);
break;
}
return 0;
}
static inline int ubus_atm_stats(char **value, char *stat_mod, void *data)
{
json_object *res = NULL;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct atm_args *)data)->device, String}}, 1, &res);
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", stat_mod);
if ((*value)[0] == '\0')
*value = "0";
return 0;
}
/*#Device.ATM.Link.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/
static int get_atm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
ubus_atm_stats(value, "rx_bytes", data);
return 0;
}
/*#Device.ATM.Link.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/
static int get_atm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
ubus_atm_stats(value, "tx_bytes", data);
return 0;
}
/*#Device.ATM.Link.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/
static int get_atm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
ubus_atm_stats(value, "rx_packets", data);
return 0;
}
/*#Device.ATM.Link.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/
static int get_atm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
ubus_atm_stats(value, "tx_packets", data);
return 0;
}
/*#Device.ATM.Link.{i}.Enable!UCI:dsl/atm-device,@i-1/enabled*/
static int get_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((((struct atm_args *)data)->sections)->config_section, "enabled", "1");
return 0;
}
static int set_atm_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;
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "enabled", b ? "1" : "0");
return 0;
}
return 0;
}
/*#Device.ATM.Link.{i}.Status!SYSFS:/sys/class/net/@Name/operstate*/
static int get_atm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return get_net_device_status(((struct atm_args *)data)->device, value);
}
/*#Device.ATM.Link.{i}.Alias!UCI:dmmap_dsl/atm-device,@i-1/atmlinkalias*/
static int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return bbf_get_alias(ctx, (((struct atm_args *)data)->sections)->dmmap_section, "atmlinkalias", instance, value);
}
static int set_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
return bbf_set_alias(ctx, (((struct atm_args *)data)->sections)->dmmap_section, "atmlinkalias", instance, value);
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/*** ATM. ***/
DMOBJ tATMObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
{"Link", &DMWRITE, add_atm_link, delete_atm_link, NULL, browseAtmLinkInst, NULL, NULL, tATMLinkObj, tATMLinkParams, NULL, BBFDM_BOTH, NULL},
{0}
};
/*** ATM.Link. ***/
DMOBJ tATMLinkObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tATMLinkStatsParams, NULL, BBFDM_BOTH, NULL},
{0}
};
DMLEAF tATMLinkParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/
{"Alias", &DMWRITE, DMT_STRING, get_atm_alias, set_atm_alias, BBFDM_BOTH, DM_FLAG_UNIQUE},
{"Enable", &DMWRITE, DMT_BOOL, get_atm_enable, set_atm_enable, BBFDM_BOTH},
{"Name", &DMREAD, DMT_STRING, get_atm_link_name, NULL, BBFDM_BOTH, DM_FLAG_UNIQUE|DM_FLAG_LINKER},
{"Status", &DMREAD, DMT_STRING, get_atm_status, NULL, BBFDM_BOTH},
{"LowerLayers", &DMWRITE, DMT_STRING, get_atm_lower_layer, set_atm_lower_layer, BBFDM_BOTH, DM_FLAG_REFERENCE},
{"LinkType", &DMWRITE, DMT_STRING, get_atm_link_type, set_atm_link_type, BBFDM_BOTH},
{"DestinationAddress", &DMWRITE, DMT_STRING, get_atm_destination_address, set_atm_destination_address, BBFDM_BOTH},
{"Encapsulation", &DMWRITE, DMT_STRING, get_atm_encapsulation, set_atm_encapsulation, BBFDM_BOTH},
{0}
};
/*** ATM.Link.Stats. ***/
DMLEAF tATMLinkStatsParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/
{"BytesSent", &DMREAD, DMT_UNLONG, get_atm_stats_bytes_sent, NULL, BBFDM_BOTH},
{"BytesReceived", &DMREAD, DMT_UNLONG, get_atm_stats_bytes_received, NULL, BBFDM_BOTH},
{"PacketsSent", &DMREAD, DMT_UNLONG, get_atm_stats_pack_sent, NULL, BBFDM_BOTH},
{"PacketsReceived", &DMREAD, DMT_UNLONG, get_atm_stats_pack_received, NULL, BBFDM_BOTH},
{0}
};

View file

@ -1,24 +0,0 @@
/*
* Copyright (C) 2019 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: Anis Ellouze <anis.ellouze@pivasoftware.com>
*
*/
#ifndef __ATM_H
#define __ATM_H
#include "libbbfdm-api/dmcommon.h"
extern DMOBJ tATMObj[];
extern DMOBJ tATMLinkObj[];
extern DMLEAF tATMLinkParams[];
extern DMLEAF tATMLinkStatsParams[];
void remove_device_from_interface(struct uci_section *interface_s, char *device);
#endif

View file

@ -18,15 +18,11 @@
#include "ethernet.h"
#include "bridging.h"
#include "wifi.h"
#include "atm.h"
#include "ptm.h"
#include "dhcpv4.h"
#include "nat.h"
#include "ppp.h"
#include "routing.h"
#include "firewall.h"
#include "dsl.h"
#include "fast.h"
#include "dhcpv6.h"
#include "interfacestack.h"
#include "qos.h"
@ -96,10 +92,6 @@ DMOBJ tDeviceObj[] = {
{"Bridging", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tBridgingObj, tBridgingParams, NULL, BBFDM_BOTH, NULL},
{"IP", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tIPObj, tIPParams, NULL, BBFDM_BOTH, NULL},
{"Ethernet", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tEthernetObj, tEthernetParams, NULL, BBFDM_BOTH, NULL},
{"DSL", &DMREAD, NULL, NULL, "file:/etc/config/dsl", NULL, NULL, NULL, tDSLObj, tDSLParams, NULL, BBFDM_BOTH, NULL},
{"FAST", &DMREAD, NULL, NULL, "ubus:fast", NULL, NULL, NULL, tFASTObj, tFASTParams, NULL, BBFDM_BOTH, NULL},
{"ATM", &DMREAD, NULL, NULL, "file:/etc/config/dsl", NULL, NULL, NULL, tATMObj, NULL, NULL, BBFDM_BOTH, NULL},
{"PTM", &DMREAD, NULL, NULL, "file:/etc/config/dsl", NULL, NULL, NULL, tPTMObj, NULL, NULL, BBFDM_BOTH, NULL},
{"DHCPv4", &DMREAD, NULL, NULL, "file:/lib/netifd/proto/dhcp.sh,/etc/config/dhcp", NULL, NULL, NULL, tDHCPv4Obj, tDHCPv4Params, NULL, BBFDM_BOTH, NULL},
{"DHCPv6", &DMREAD, NULL, NULL, "file:/lib/netifd/proto/dhcpv6.sh,/etc/config/dhcp", NULL, NULL, NULL, tDHCPv6Obj, tDHCPv6Params, NULL, BBFDM_BOTH, NULL},
{"NAT", &DMREAD, NULL, NULL, "file:/etc/config/firewall", NULL, NULL, NULL, tNATObj, tNATParams, NULL, BBFDM_BOTH, NULL},

File diff suppressed because it is too large Load diff

View file

@ -1,40 +0,0 @@
/*
* Copyright (C) 2019 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: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#ifndef __DSL_H
#define __DSL_H
#include "libbbfdm-api/dmcommon.h"
extern DMOBJ tDSLObj[];
extern DMLEAF tDSLParams[];
extern DMOBJ tDSLLineObj[];
extern DMLEAF tDSLLineParams[];
extern DMOBJ tDSLLineStatsObj[];
extern DMLEAF tDSLLineStatsParams[];
extern DMLEAF tDSLLineStatsTotalParams[];
extern DMLEAF tDSLLineStatsShowtimeParams[];
extern DMLEAF tDSLLineStatsLastShowtimeParams[];
extern DMLEAF tDSLLineStatsCurrentDayParams[];
extern DMLEAF tDSLLineStatsQuarterHourParams[];
extern DMOBJ tDSLChannelObj[];
extern DMLEAF tDSLChannelParams[];
extern DMOBJ tDSLChannelStatsObj[];
extern DMLEAF tDSLChannelStatsParams[];
extern DMLEAF tDSLChannelStatsTotalParams[];
extern DMLEAF tDSLChannelStatsShowtimeParams[];
extern DMLEAF tDSLChannelStatsLastShowtimeParams[];
extern DMLEAF tDSLChannelStatsCurrentDayParams[];
extern DMLEAF tDSLChannelStatsQuarterHourParams[];
char *get_value_with_argument(char *command1, char *id, char *command2, char *argument, char *key);
int get_line_linkstatus(char *method, char *id, char **value);
#endif //__DSL_H

File diff suppressed because it is too large Load diff

View file

@ -1,28 +0,0 @@
/*
* Copyright (C) 2020 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: Jani Juvan <jani.juvan@iopsys.eu>
*/
#ifndef __FAST_H
#define __FAST_H
#include "libbbfdm-api/dmcommon.h"
extern DMOBJ tFASTObj[];
extern DMLEAF tFASTParams[];
extern DMOBJ tFASTLineObj[];
extern DMLEAF tFASTLineParams[];
extern DMOBJ tFASTLineStatsObj[];
extern DMLEAF tFASTLineStatsParams[];
extern DMLEAF tFASTLineStatsTotalParams[];
extern DMLEAF tFASTLineStatsShowtimeParams[];
extern DMLEAF tFASTLineStatsLastShowtimeParams[];
extern DMLEAF tFASTLineStatsCurrentDayParams[];
extern DMLEAF tFASTLineStatsQuarterHourParams[];
#endif //__FAST_H

View file

@ -1,282 +0,0 @@
/*
* Copyright (C) 2019 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: Anis Ellouze <anis.ellouze@pivasoftware.com>
*
*/
#include "atm.h"
#include "ptm.h"
struct ptm_args
{
struct dmmap_dup *sections;
char *device;
};
/**************************************************************************
* INIT
***************************************************************************/
static inline int init_ptm_link(struct ptm_args *args, struct dmmap_dup *s, char *device)
{
args->sections = s;
args->device = device;
return 0;
}
/*************************************************************
* ENTRY METHOD
*************************************************************/
/*#Device.PTM.Link.{i}.!UCI:dsl/ptm-device/dmmap_dsl*/
static int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *device;
struct ptm_args curr_ptm_args = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dsl", "ptm-device", "dmmap_dsl", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "device", &device);
init_ptm_link(&curr_ptm_args, p, device);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "ptmlinkinstance", "ptmlinkalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ptm_args, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*************************************************************
* ADD OBJ
*************************************************************/
static int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_ptm = NULL;
char ptm_device[16];
snprintf(ptm_device, sizeof(ptm_device), "ptm%s", *instance);
dmuci_set_value("dsl", ptm_device, "", "ptm-device");
dmuci_set_value("dsl", ptm_device, "name", "PTM");
dmuci_set_value("dsl", ptm_device, "device", ptm_device);
dmuci_set_value("dsl", ptm_device, "enabled", "0");
dmuci_add_section_bbfdm("dmmap_dsl", "ptm-device", &dmmap_ptm);
dmuci_set_value_by_section(dmmap_ptm, "section_name", ptm_device);
dmuci_set_value_by_section(dmmap_ptm, "ptmlinkinstance", *instance);
return 0;
}
static int delete_ptm_link(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:
uci_foreach_option_cont("network", "interface", "device", ((struct ptm_args *)data)->device, s) {
remove_device_from_interface(stmp, ((struct ptm_args *)data)->device);
}
dmuci_delete_by_section((((struct ptm_args *)data)->sections)->dmmap_section, NULL, NULL);
dmuci_delete_by_section((((struct ptm_args *)data)->sections)->config_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("dsl", "ptm-device", stmp, s) {
struct uci_section *ns = NULL;
char *device = NULL;
dmuci_get_value_by_section_string(s, "device", &device);
if (DM_STRLEN(device) == 0)
continue;
uci_foreach_option_cont("network", "interface", "device", device, ns) {
remove_device_from_interface(ns, device);
}
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(s), &ns);
dmuci_delete_by_section(ns, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
/*#Device.PTM.Link.{i}.Enable!UCI:dsl/ptm-device,@i-1/enabled*/
static int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((((struct ptm_args *)data)->sections)->config_section, "enabled", "1");
return 0;
}
static int set_ptm_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;
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->config_section, "enabled", b ? "1" : "0");
return 0;
}
return 0;
}
/*#Device.PTM.Link.{i}.Status!SYSFS:/sys/class/net/@Name/operstate*/
static int get_ptm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return get_net_device_status(((struct ptm_args *)data)->device, value);
}
/*#Device.PTM.Link.{i}.Alias!UCI:dmmap_dsl/ptm-device,@i-1/ptmlinkalias*/
static int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return bbf_get_alias(ctx, (((struct ptm_args *)data)->sections)->dmmap_section, "ptmlinkalias", instance, value);
}
static int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
return bbf_set_alias(ctx, (((struct ptm_args *)data)->sections)->dmmap_section, "ptmlinkalias", instance, value);
}
/*#Device.PTM.Link.{i}.Name!UCI:dsl/ptm-device,@i-1/name*/
static int get_ptm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmstrdup(((struct ptm_args *)data)->device);
return 0;
}
static int get_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((((struct ptm_args *)data)->sections)->dmmap_section, "LowerLayers", value);
if ((*value)[0] == '\0') {
char ptm_file[128] = {0};
adm_entry_get_reference_param(ctx, "Device.FAST.Line.*.Status", "Up", value);
if (DM_STRLEN(*value))
return 0;
snprintf(ptm_file, sizeof(ptm_file), "/sys/class/net/ptm%ld", DM_STRTOL(instance) - 1);
if (folder_exists(ptm_file)) {
adm_entry_get_reference_param(ctx, "Device.DSL.Channel.*.Name", "1", value);
if (DM_STRLEN(*value))
return 0;
}
adm_entry_get_reference_param(ctx, "Device.FAST.Line.*.Name", "1", value);
// Store LowerLayers value
dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "LowerLayers", *value);
} else {
if (!adm_entry_object_exists(ctx, *value))
*value = "";
}
return 0;
}
static int set_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct dm_reference reference = {0};
bbf_get_reference_args(value, &reference);
switch (action) {
case VALUECHECK:
if (DM_LSTRNCMP(reference.path, "Device.DSL.Channel.1", strlen("Device.DSL.Channel.1")) != 0 && DM_LSTRNCMP(reference.path, "Device.FAST.Line.1", strlen("Device.FAST.Line.1")) != 0)
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "LowerLayers", reference.path);
break;
}
return 0;
}
static inline int ubus_ptm_stats(char **value, const char *stat_mod, void *data)
{
json_object *res = NULL;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct ptm_args *)data)->device, String}}, 1, &res);
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 2, "statistics", stat_mod);
if ((*value)[0] == '\0')
*value = "0";
return 0;
}
/*#Device.PTM.Link.{i}.Stats.BytesReceived!UBUS:network.device/status/name,@Name/statistics.rx_bytes*/
static int get_ptm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ubus_ptm_stats(value, "rx_bytes", data);
}
/*#Device.PTM.Link.{i}.Stats.BytesSent!UBUS:network.device/status/name,@Name/statistics.tx_bytes*/
static int get_ptm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ubus_ptm_stats(value, "tx_bytes", data);
}
/*#Device.PTM.Link.{i}.Stats.PacketsReceived!UBUS:network.device/status/name,@Name/statistics.rx_packets*/
static int get_ptm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ubus_ptm_stats(value, "rx_packets", data);
}
/*#Device.PTM.Link.{i}.Stats.PacketsSent!UBUS:network.device/status/name,@Name/statistics.tx_packets*/
static int get_ptm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ubus_ptm_stats(value, "tx_packets", data);
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/* *** Device.PTM. *** */
DMOBJ tPTMObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys, version*/
{"Link", &DMWRITE, add_ptm_link, delete_ptm_link, NULL, browsePtmLinkInst, NULL, NULL, tPTMLinkObj, tPTMLinkParams, NULL, BBFDM_BOTH, NULL},
{0}
};
/* *** Device.PTM.Link.{i}. *** */
DMOBJ tPTMLinkObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys, version*/
{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tPTMLinkStatsParams, NULL, BBFDM_BOTH, NULL},
{0}
};
DMLEAF tPTMLinkParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type, version*/
{"Enable", &DMWRITE, DMT_BOOL, get_ptm_enable, set_ptm_enable, BBFDM_BOTH},
{"Status", &DMREAD, DMT_STRING, get_ptm_status, NULL, BBFDM_BOTH},
{"Alias", &DMWRITE, DMT_STRING, get_ptm_alias, set_ptm_alias, BBFDM_BOTH, DM_FLAG_UNIQUE},
{"Name", &DMREAD, DMT_STRING, get_ptm_link_name, NULL, BBFDM_BOTH, DM_FLAG_UNIQUE|DM_FLAG_LINKER},
{"LowerLayers", &DMWRITE, DMT_STRING, get_ptm_lower_layer, set_ptm_lower_layer, BBFDM_BOTH, DM_FLAG_REFERENCE},
{0}
};
/* *** Device.PTM.Link.{i}.Stats. *** */
DMLEAF tPTMLinkStatsParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type, version*/
{"BytesSent", &DMREAD, DMT_UNLONG, get_ptm_stats_bytes_sent, NULL, BBFDM_BOTH},
{"BytesReceived", &DMREAD, DMT_UNLONG, get_ptm_stats_bytes_received, NULL, BBFDM_BOTH},
{"PacketsSent", &DMREAD, DMT_UNLONG, get_ptm_stats_pack_sent, NULL, BBFDM_BOTH},
{"PacketsReceived", &DMREAD, DMT_UNLONG, get_ptm_stats_pack_received, NULL, BBFDM_BOTH},
{0}
};

View file

@ -1,22 +0,0 @@
/*
* Copyright (C) 2019 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: Anis Ellouze <anis.ellouze@pivasoftware.com>
*
*/
#ifndef __PTM_H
#define __PTM_H
#include "libbbfdm-api/dmcommon.h"
extern DMOBJ tPTMObj[];
extern DMOBJ tPTMLinkObj[];
extern DMLEAF tPTMLinkStatsParams[];
extern DMLEAF tPTMLinkParams[];
#endif

View file

@ -170,6 +170,16 @@
"dm_files": [
"bbf_plugin/nat_porttrigger.c"
]
},
{
"repo": "https://dev.iopsys.eu/hal/dslmngr.git",
"proto": "git",
"dm_files": [
"bbf_plugin/dsl.c",
"bbf_plugin/fast.c",
"bbf_plugin/atm.c",
"bbf_plugin/ptm.c"
]
}
],
"output": {