Skip to content

Commit

Permalink
Merge pull request #1293 from IRATI/e2ens
Browse files Browse the repository at this point in the history
Merge e2ens into master
  • Loading branch information
edugrasa authored Jun 3, 2019
2 parents df6c801 + 3a10e63 commit 990d8d9
Show file tree
Hide file tree
Showing 13 changed files with 608 additions and 287 deletions.
143 changes: 93 additions & 50 deletions kernel/dtcp-ps-default.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,69 +234,108 @@ int default_rate_reduction(struct dtcp_ps * ps, const struct pci * pci)
return 0;
}

int default_rtt_estimator(struct dtcp_ps * ps, seq_num_t sn)
static int rtt_calculation(struct dtcp_ps * ps, timeout_t start_time)
{
struct dtcp * dtcp;
uint_t rtt, new_sample, srtt, rttvar, trmsecs;
timeout_t start_time, a;
int abs;
struct dtcp * dtcp;
uint_t rtt, new_sample, srtt, rttvar, trmsecs;
timeout_t a;
int abs;

if (!ps)
return -1;
dtcp = ps->dm;
if (!dtcp)
return -1;
if (!ps)
return -1;
dtcp = ps->dm;
if (!dtcp)
return -1;

LOG_DBG("RTT Estimator...");
new_sample = jiffies_to_msecs(jiffies - start_time);

start_time = rtxq_entry_timestamp(dtcp->parent->rtxq, sn);
if (start_time == 0) {
LOG_DBG("RTTestimator: PDU %u has been retransmitted", sn);
return 0;
}
spin_lock_bh(&dtcp->parent->sv_lock);

new_sample = jiffies_to_msecs(jiffies - start_time);
rtt = dtcp->sv->rtt;
srtt = dtcp->sv->srtt;
rttvar = dtcp->sv->rttvar;
a = dtcp->parent->sv->A;

if (!rtt) {
rtt = new_sample;
rttvar = new_sample >> 1;
srtt = new_sample;
} else {
/* RTT <== RTT * (112/128) + SAMPLE * (16/128)*/
rtt = (rtt * 112 + (new_sample << 4)) >> 7;
abs = srtt - new_sample;
abs = abs < 0 ? -abs : abs;
rttvar = ((3 * rttvar) >> 2) + (((uint_t)abs) >> 2);
}

spin_lock_bh(&dtcp->parent->sv_lock);
/* FIXME: k, G, alpha and betha should be parameters passed to the
* policy set. Probably moving them to ps->priv */

rtt = dtcp->sv->rtt;
srtt = dtcp->sv->srtt;
rttvar = dtcp->sv->rttvar;
a = dtcp->parent->sv->A;
/* k * rttvar = 4 * rttvar */
trmsecs = rttvar << 2;
/* G is 0.1s according to RFC6298, then 100ms */
trmsecs = 100 > trmsecs ? 100 : trmsecs;
trmsecs += srtt + jiffies_to_msecs(a);
/* RTO (tr) less than 1s? (not for the common policy) */
/*trmsecs = trmsecs < 1000 ? 1000 : trmsecs;*/

if (!rtt) {
rtt = new_sample;
rttvar = new_sample >> 1;
srtt = new_sample;
} else {
/* RTT <== RTT * (112/128) + SAMPLE * (16/128)*/
rtt = (rtt * 112 + (new_sample << 4)) >> 7;
abs = srtt - new_sample;
abs = abs < 0 ? -abs : abs;
rttvar = ((3 * rttvar) >> 2) + (((uint_t)abs) >> 2);
}
dtcp->sv->rtt = rtt;
dtcp->sv->rttvar = rttvar;
dtcp->sv->srtt = srtt;
dtcp->parent->sv->tr = msecs_to_jiffies(trmsecs);

/*FIXME: k, G, alpha and betha should be parameters passed to the policy
* set. Probably moving them to ps->priv */
LOG_DBG("RTT estimated at %u", rtt);

/* k * rttvar = 4 * rttvar */
trmsecs = rttvar << 2;
/* G is 0.1s according to RFC6298, then 100ms */
trmsecs = 100 > trmsecs ? 100 : trmsecs;
trmsecs += srtt + jiffies_to_msecs(a);
/* RTO (tr) less than 1s? (not for the common policy) */
/*trmsecs = trmsecs < 1000 ? 1000 : trmsecs;*/
spin_unlock_bh(&dtcp->parent->sv_lock);

dtcp->sv->rtt = rtt;
dtcp->sv->rttvar = rttvar;
dtcp->sv->srtt = srtt;
dtcp->parent->sv->tr = msecs_to_jiffies(trmsecs);
return 0;
}

spin_unlock_bh(&dtcp->parent->sv_lock);
int default_rtt_estimator(struct dtcp_ps * ps, seq_num_t sn)
{
struct dtcp * dtcp;
timeout_t start_time;

LOG_DBG("New RTT %u; New Tr: %u ms", rtt, trmsecs);
if (!ps)
return -1;
dtcp = ps->dm;
if (!dtcp)
return -1;

return 0;
LOG_DBG("RTT Estimator...");

start_time = rtxq_entry_timestamp(dtcp->parent->rtxq, sn);
if (start_time == 0) {
LOG_DBG("RTTestimator: PDU %u has been retransmitted", sn);
return 0;
}

rtt_calculation(ps, start_time);

return 0;
}

int default_rtt_estimator_nortx(struct dtcp_ps * ps, seq_num_t sn)
{
struct dtcp * dtcp;
timeout_t start_time;

if (!ps)
return -1;
dtcp = ps->dm;
if (!dtcp)
return -1;

LOG_DBG("RTT Estimator with only flow control...");

start_time = rttq_entry_timestamp(dtcp->parent->rttq, sn);
if (start_time == 0) {
return 0;
}

rtt_calculation(ps, start_time);

return 0;
}

struct ps_base * dtcp_ps_default_create(struct rina_component * component)
Expand All @@ -313,7 +352,11 @@ struct ps_base * dtcp_ps_default_create(struct rina_component * component)
ps->priv = NULL;
ps->flow_init = NULL;
ps->lost_control_pdu = default_lost_control_pdu;
ps->rtt_estimator = default_rtt_estimator;
if (ps->rtx_ctrl) {
ps->rtt_estimator = default_rtt_estimator;
} else {
ps->rtt_estimator = default_rtt_estimator_nortx;
}
ps->retransmission_timer_expiry = NULL;
ps->received_retransmission = NULL;
ps->sender_ack = default_sender_ack;
Expand Down
2 changes: 2 additions & 0 deletions kernel/dtcp-ps-default.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ int default_rate_reduction(struct dtcp_ps * ps, const struct pci * pci);

int default_rtt_estimator(struct dtcp_ps * ps, seq_num_t sn);

int default_rtt_estimator_nortx(struct dtcp_ps * ps, seq_num_t sn);

#endif /* RINA_DTCP_PS_COMMON_H */
84 changes: 43 additions & 41 deletions kernel/dtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,22 +419,21 @@ static int rcv_ack(struct dtcp * dtcp,
return ret;
}

static int rcv_flow_ctl(struct dtcp * dtcp,
struct du * du)
static int update_window_and_rate(struct dtcp * dtcp,
struct du * du)
{
uint_t rt;
uint_t tf;

rt = pci_control_sndr_rate(&du->pci);
tf = pci_control_time_frame(&du->pci);

spin_lock_bh(&dtcp->parent->sv_lock);
if(dtcp_window_based_fctrl(dtcp->cfg)) {
dtcp->sv->snd_rt_wind_edge =
pci_control_new_rt_wind_edge(&du->pci);
pci_control_new_rt_wind_edge(&du->pci);
}

if(dtcp_rate_based_fctrl(dtcp->cfg)) {
rt = pci_control_sndr_rate(&du->pci);
tf = pci_control_time_frame(&du->pci);
if(tf && rt) {
dtcp->sv->sndr_rate = rt;
dtcp->sv->time_unit = tf;
Expand All @@ -444,25 +443,52 @@ static int rcv_flow_ctl(struct dtcp * dtcp,
rt, tf);
}
}

LOG_DBG("New SND RWE: %u, New LWE: %u, DTCP: %pK",
dtcp->sv->snd_rt_wind_edge, dtcp->sv->snd_lft_win, dtcp);
spin_unlock_bh(&dtcp->parent->sv_lock);

push_pdus_rmt(dtcp);

LOG_DBG("DTCP received FC (CPU: %d)", smp_processor_id());
dump_we(dtcp, &du->pci);

du_destroy(du);

return 0;
}

static int rcv_flow_ctl(struct dtcp * dtcp,
struct du * du)
{
struct dtcp_ps * ps;
seq_num_t seq;
uint_t credit;

/* Update RTT estimation */
credit = dtcp->sv->sndr_credit;
seq = pci_control_new_rt_wind_edge(&du->pci);

rcu_read_lock();
ps = container_of(rcu_dereference(dtcp->base.ps),
struct dtcp_ps, base);

LOG_DBG("DTCP received FC: New RWE: %u, Credit: %u, SN to drop: %u",
seq, credit, seq-credit);
if (!ps->rtx_ctrl && ps->rtt_estimator)
ps->rtt_estimator(ps, seq - credit);

rcu_read_unlock();

if (dtcp->parent->rttq) {
rttq_drop(dtcp->parent->rttq, seq-credit);
}

return update_window_and_rate(dtcp, du);
}

static int rcv_ack_and_flow_ctl(struct dtcp * dtcp,
struct du * du)
{
struct dtcp_ps * ps;
seq_num_t seq;
uint_t rt;
uint_t tf;

seq = pci_control_ack_seq_num(&du->pci);

Expand All @@ -476,37 +502,9 @@ static int rcv_ack_and_flow_ctl(struct dtcp * dtcp,
LOG_ERR("Could not update RTXQ and LWE");
rcu_read_unlock();

spin_lock_bh(&dtcp->parent->sv_lock);
if(dtcp_window_based_fctrl(dtcp->cfg)) {
dtcp->sv->snd_rt_wind_edge =
pci_control_new_rt_wind_edge(&du->pci);
LOG_DBG("Right Window Edge: %u", dtcp->sv->snd_rt_wind_edge);
}

if(dtcp_rate_based_fctrl(dtcp->cfg)) {
rt = pci_control_sndr_rate(&du->pci);
tf = pci_control_time_frame(&du->pci);

if(tf && rt) {
dtcp->sv->sndr_rate = rt;
dtcp->sv->time_unit = tf;
LOG_DBG("Rate based fields sets on flow ctl and "
"ack, rate: %u, time: %u",
rt, tf);
}
}
spin_unlock_bh(&dtcp->parent->sv_lock);

LOG_DBG("Calling CWQ_deliver for DTCP: %pK", dtcp);
push_pdus_rmt(dtcp);

/* FIXME: Verify values for the receiver side */
LOG_DBG("DTCP received ACK-FC (CPU: %d)", smp_processor_id());
dump_we(dtcp, &du->pci);

du_destroy(du);

return 0;
return update_window_and_rate(dtcp, du);
}

int dtcp_common_rcv_control(struct dtcp * dtcp, struct du * du)
Expand Down Expand Up @@ -912,7 +910,11 @@ int dtcp_select_policy_set(struct dtcp * dtcp,
ps->rate_reduction = default_rate_reduction;
}
if (!ps->rtt_estimator) {
ps->rtt_estimator = default_rtt_estimator;
if (ps->rtx_ctrl) {
ps->rtt_estimator = default_rtt_estimator;
} else {
ps->rtt_estimator = default_rtt_estimator_nortx;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions kernel/dtp-ps-default.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ int default_sender_inactivity_timer(struct dtp_ps * ps)
snd_rt_win = dtcp->sv->snd_rt_wind_edge;
next_send = dtp->sv->seq_nr_to_send;
dtcp->sv->snd_rt_wind_edge = next_send + init_credit;
if (dtp->rttq) {
rttq_flush(dtp->rttq);
}

LOG_DBG("Current values:\n\tinit_credit: %u "
"max_sent: %u snd_rt_win: %u next_send: %u",
Expand Down
Loading

0 comments on commit 990d8d9

Please sign in to comment.