summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/dt.c
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2018-10-06 18:06:47 +0200
committerDimitri Staessens <[email protected]>2018-10-06 18:06:47 +0200
commit0b2e5c5410580c755cef02114e51f15b19cfaffa (patch)
tree63d684e6057c9caa43739b599d54a72f9959d4f8 /src/ipcpd/normal/dt.c
parentbfc29ca20406ccd69363b0f9796987534318e7ae (diff)
parentd9ad3852613cda026d4520b5c608ada7433dd7d9 (diff)
downloadouroboros-0b2e5c5410580c755cef02114e51f15b19cfaffa.tar.gz
ouroboros-0b2e5c5410580c755cef02114e51f15b19cfaffa.zip
Merge branch 'testing' into be
Diffstat (limited to 'src/ipcpd/normal/dt.c')
-rw-r--r--src/ipcpd/normal/dt.c158
1 files changed, 122 insertions, 36 deletions
diff --git a/src/ipcpd/normal/dt.c b/src/ipcpd/normal/dt.c
index b9d8934e..dc7343f1 100644
--- a/src/ipcpd/normal/dt.c
+++ b/src/ipcpd/normal/dt.c
@@ -20,15 +20,17 @@
* Foundation, Inc., http://www.fsf.org/about/contact/.
*/
+#if defined(__linux__) || defined(__CYGWIN__)
+#define _DEFAULT_SOURCE
+#else
#define _POSIX_C_SOURCE 200112L
+#endif
#include "config.h"
#define DT "dt"
#define OUROBOROS_PREFIX DT
-/* FIXME: fix #defines and remove endian.h include. */
-#include <ouroboros/endian.h>
#include <ouroboros/bitmap.h>
#include <ouroboros/errno.h>
#include <ouroboros/logs.h>
@@ -42,10 +44,9 @@
#include "connmgr.h"
#include "ipcp.h"
#include "dt.h"
-#include "dt_pci.h"
#include "pff.h"
#include "routing.h"
-#include "sdu_sched.h"
+#include "psched.h"
#include "comp.h"
#include "fa.h"
@@ -64,13 +65,96 @@
#endif
struct comp_info {
- void (* post_sdu)(void * comp, struct shm_du_buff * sdb);
+ void (* post_packet)(void * comp, struct shm_du_buff * sdb);
void * comp;
char * name;
};
+/* Abstract syntax */
+enum dtp_fields {
+ DTP_DST = 0, /* DST ADDRESS */
+ DTP_QOS, /* QOS ID */
+ DTP_DEID, /* DST Endpoint ID */
+ DTP_TTL, /* TTL FIELD */
+ DTP_NUM_FIELDS /* Number of fields */
+};
+
+/* Fixed field lengths */
+#define TTL_LEN 1
+#define QOS_LEN 1
+
+struct dt_pci {
+ uint64_t dst_addr;
+ qoscube_t qc;
+ uint8_t ttl;
+ uint32_t eid;
+};
+
+struct {
+ uint8_t addr_size;
+ uint8_t eid_size;
+ size_t head_size;
+
+ /* Offsets */
+ size_t qc_o;
+ size_t ttl_o;
+ size_t eid_o;
+
+ /* Initial TTL value */
+ uint8_t max_ttl;
+} dt_pci_info;
+
+static int dt_pci_ser(struct shm_du_buff * sdb,
+ struct dt_pci * dt_pci)
+{
+ uint8_t * head;
+ uint8_t ttl = dt_pci_info.max_ttl;
+
+ assert(sdb);
+ assert(dt_pci);
+
+ head = shm_du_buff_head_alloc(sdb, dt_pci_info.head_size);
+ if (head == NULL)
+ return -EPERM;
+
+ /* FIXME: Add check and operations for Big Endian machines. */
+ memcpy(head, &dt_pci->dst_addr, dt_pci_info.addr_size);
+ memcpy(head + dt_pci_info.qc_o, &dt_pci->qc, QOS_LEN);
+ memcpy(head + dt_pci_info.ttl_o, &ttl, TTL_LEN);
+ memcpy(head + dt_pci_info.eid_o, &dt_pci->eid, dt_pci_info.eid_size);
+
+ return 0;
+}
+
+static void dt_pci_des(struct shm_du_buff * sdb,
+ struct dt_pci * dt_pci)
+{
+ uint8_t * head;
+
+ assert(sdb);
+ assert(dt_pci);
+
+ head = shm_du_buff_head(sdb);
+
+ /* Decrease TTL */
+ --*(head + dt_pci_info.ttl_o);
+
+ /* FIXME: Add check and operations for Big Endian machines. */
+ memcpy(&dt_pci->dst_addr, head, dt_pci_info.addr_size);
+ memcpy(&dt_pci->qc, head + dt_pci_info.qc_o, QOS_LEN);
+ memcpy(&dt_pci->ttl, head + dt_pci_info.ttl_o, TTL_LEN);
+ memcpy(&dt_pci->eid, head + dt_pci_info.eid_o, dt_pci_info.eid_size);
+}
+
+static void dt_pci_shrink(struct shm_du_buff * sdb)
+{
+ assert(sdb);
+
+ shm_du_buff_head_release(sdb, dt_pci_info.head_size);
+}
+
struct {
- struct sdu_sched * sdu_sched;
+ struct psched * psched;
struct pff * pff[QOS_CUBE_MAX];
struct routing_i * routing[QOS_CUBE_MAX];
@@ -337,24 +421,25 @@ static void handle_event(void * self,
#ifdef IPCP_FLOW_STATS
stat_used(c->flow_info.fd, c->conn_info.addr);
#endif
- sdu_sched_add(dt.sdu_sched, c->flow_info.fd);
- log_dbg("Added fd %d to SDU scheduler.", c->flow_info.fd);
+ psched_add(dt.psched, c->flow_info.fd);
+ log_dbg("Added fd %d to packet scheduler.", c->flow_info.fd);
break;
case NOTIFY_DT_CONN_DEL:
#ifdef IPCP_FLOW_STATS
stat_used(c->flow_info.fd, INVALID_ADDR);
#endif
- sdu_sched_del(dt.sdu_sched, c->flow_info.fd);
- log_dbg("Removed fd %d from SDU scheduler.", c->flow_info.fd);
+ psched_del(dt.psched, c->flow_info.fd);
+ log_dbg("Removed fd %d from "
+ "packet scheduler.", c->flow_info.fd);
break;
default:
break;
}
}
-static void sdu_handler(int fd,
- qoscube_t qc,
- struct shm_du_buff * sdb)
+static void packet_handler(int fd,
+ qoscube_t qc,
+ struct shm_du_buff * sdb)
{
struct dt_pci dt_pci;
int ret;
@@ -407,7 +492,7 @@ static void sdu_handler(int fd,
ret = ipcp_flow_write(ofd, sdb);
if (ret < 0) {
- log_dbg("Failed to write SDU to fd %d.", ofd);
+ log_dbg("Failed to write packet to fd %d.", ofd);
if (ret == -EFLOWDOWN)
notifier_event(NOTIFY_DT_FLOW_DOWN, &ofd);
ipcp_sdb_release(sdb);
@@ -476,7 +561,7 @@ static void sdu_handler(int fd,
return;
}
- if (dt.comps[dt_pci.eid].post_sdu == NULL) {
+ if (dt.comps[dt_pci.eid].post_packet == NULL) {
log_err("No registered component on eid %d.",
dt_pci.eid);
ipcp_sdb_release(sdb);
@@ -512,7 +597,8 @@ static void sdu_handler(int fd,
pthread_mutex_unlock(&dt.stat[dt_pci.eid].lock);
#endif
- dt.comps[dt_pci.eid].post_sdu(dt.comps[dt_pci.eid].comp, sdb);
+ dt.comps[dt_pci.eid].post_packet(dt.comps[dt_pci.eid].comp,
+ sdb);
}
}
@@ -555,10 +641,14 @@ int dt_init(enum pol_routing pr,
info.pref_syntax = PROTO_FIXED;
info.addr = ipcpi.dt_addr;
- if (dt_pci_init(addr_size, eid_size, max_ttl)) {
- log_err("Failed to init shm dt_pci.");
- goto fail_pci_init;
- }
+ dt_pci_info.addr_size = addr_size;
+ dt_pci_info.eid_size = eid_size;
+ dt_pci_info.max_ttl = max_ttl;
+
+ dt_pci_info.qc_o = dt_pci_info.addr_size;
+ dt_pci_info.ttl_o = dt_pci_info.qc_o + QOS_LEN;
+ dt_pci_info.eid_o = dt_pci_info.ttl_o + TTL_LEN;
+ dt_pci_info.head_size = dt_pci_info.eid_o + dt_pci_info.eid_size;
if (notifier_reg(handle_event, NULL)) {
log_err("Failed to register with notifier.");
@@ -642,8 +732,6 @@ int dt_init(enum pol_routing pr,
fail_connmgr_comp_init:
notifier_unreg(&handle_event);
fail_notifier_reg:
- dt_pci_fini();
- fail_pci_init:
return -1;
}
@@ -671,21 +759,19 @@ void dt_fini(void)
connmgr_comp_fini(COMPID_DT);
notifier_unreg(&handle_event);
-
- dt_pci_fini();
}
int dt_start(void)
{
- dt.sdu_sched = sdu_sched_create(sdu_handler);
- if (dt.sdu_sched == NULL) {
- log_err("Failed to create N-1 SDU scheduler.");
+ dt.psched = psched_create(packet_handler);
+ if (dt.psched == NULL) {
+ log_err("Failed to create N-1 packet scheduler.");
return -1;
}
if (pthread_create(&dt.listener, NULL, dt_conn_handle, NULL)) {
log_err("Failed to create listener thread.");
- sdu_sched_destroy(dt.sdu_sched);
+ psched_destroy(dt.psched);
return -1;
}
@@ -696,7 +782,7 @@ void dt_stop(void)
{
pthread_cancel(dt.listener);
pthread_join(dt.listener, NULL);
- sdu_sched_destroy(dt.sdu_sched);
+ psched_destroy(dt.psched);
}
int dt_reg_comp(void * comp,
@@ -716,11 +802,11 @@ int dt_reg_comp(void * comp,
return -EBADF;
}
- assert(dt.comps[res_fd].post_sdu == NULL);
+ assert(dt.comps[res_fd].post_packet == NULL);
assert(dt.comps[res_fd].comp == NULL);
assert(dt.comps[res_fd].name == NULL);
- dt.comps[res_fd].post_sdu = func;
+ dt.comps[res_fd].post_packet = func;
dt.comps[res_fd].comp = comp;
dt.comps[res_fd].name = name;
@@ -731,10 +817,10 @@ int dt_reg_comp(void * comp,
return res_fd;
}
-int dt_write_sdu(uint64_t dst_addr,
- qoscube_t qc,
- int np1_fd,
- struct shm_du_buff * sdb)
+int dt_write_packet(uint64_t dst_addr,
+ qoscube_t qc,
+ int np1_fd,
+ struct shm_du_buff * sdb)
{
int fd;
struct dt_pci dt_pci;
@@ -779,7 +865,7 @@ int dt_write_sdu(uint64_t dst_addr,
#endif
ret = ipcp_flow_write(fd, sdb);
if (ret < 0) {
- log_dbg("Failed to write SDU to fd %d.", fd);
+ log_dbg("Failed to write packet to fd %d.", fd);
if (ret == -EFLOWDOWN)
notifier_event(NOTIFY_DT_FLOW_DOWN, &fd);
goto fail_write;