...
 
Commits (116)
...@@ -22,6 +22,9 @@ build:prrt: ...@@ -22,6 +22,9 @@ build:prrt:
- which cmake - which cmake
- which gcc - which gcc
- which g++ - which g++
- cmake --version
- gcc --version
- g++ --version
- pip3 list | grep Cython - pip3 list | grep Cython
- pip3 list | grep numpy - pip3 list | grep numpy
- CC=gcc-5 CXX=g++-5 cmake . -DPRRT_TESTS=1 - CC=gcc-5 CXX=g++-5 cmake . -DPRRT_TESTS=1
...@@ -38,6 +41,28 @@ build:container: ...@@ -38,6 +41,28 @@ build:container:
- docker push $CI_REGISTRY_IMAGE:$DOCKER_TAG - docker push $CI_REGISTRY_IMAGE:$DOCKER_TAG
- docker rmi $CI_REGISTRY_IMAGE:$DOCKER_TAG - docker rmi $CI_REGISTRY_IMAGE:$DOCKER_TAG
build:container_tcp:
stage: build
tags:
- docker
script:
- export DOCKER_TAG=$(echo "$CI_BUILD_REF_NAME""_tcp" | sed 's#/#_#' | sed 's#^master$#latest#')
- docker build -t $CI_REGISTRY_IMAGE:$DOCKER_TAG --build-arg http_proxy=http://www-proxy.uni-saarland.de:3128 -f docker/Dockerfile_tcp .
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE:$DOCKER_TAG
- docker rmi $CI_REGISTRY_IMAGE:$DOCKER_TAG
build:container_xlap:
stage: build
tags:
- docker
script:
- export DOCKER_TAG=$(echo "$CI_BUILD_REF_NAME""_xlap" | sed 's#/#_#' | sed 's#^master$#latest#')
- docker build -t $CI_REGISTRY_IMAGE:$DOCKER_TAG --build-arg http_proxy=http://www-proxy.uni-saarland.de:3128 -f docker/Dockerfile_xlap .
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE:$DOCKER_TAG
- docker rmi $CI_REGISTRY_IMAGE:$DOCKER_TAG
test:prrt_mem: test:prrt_mem:
stage: test stage: test
dependencies: dependencies:
......
...@@ -10,7 +10,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) ...@@ -10,7 +10,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_C_FLAGS "-O2 -Wall -std=gnu11 -D_GNU_SOURCE -fPIC" ) set(CMAKE_C_FLAGS "-O2 -Wall -std=gnu11 -D_GNU_SOURCE -fPIC" )
set(CMAKE_C_FLAGS_DEBUG "-O0 -fsanitize=undefined -fsanitize=address -g3" ) set(CMAKE_C_FLAGS_DEBUG "-O0 -fsanitize=undefined -fsanitize=address -g3" )
set(CMAKE_CXX_FLAGS "-fstack-protector -fstack-protector-all -Wall -std=gnu++11 -D_GNU_SOURCE" ) set(CMAKE_CXX_FLAGS "-fstack-protector -fstack-protector-all -Wall -std=gnu++11 -D_GNU_SOURCE -fsanitize=undefined -fsanitize=address" )
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wall -ggdb -fsanitize=undefined -fsanitize=address -g3" ) set(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wall -ggdb -fsanitize=undefined -fsanitize=address -g3" )
set(CMAKE_CXX_FLAGS_RELEASE "-Os -Wall" ) set(CMAKE_CXX_FLAGS_RELEASE "-Os -Wall" )
......
...@@ -29,9 +29,9 @@ port = int(sys.argv[1]) ...@@ -29,9 +29,9 @@ port = int(sys.argv[1])
s = prrt.PrrtSocket(port=port) s = prrt.PrrtSocket(port=port)
while True: while True:
d = s.recv() d = s.recv().decode("utf8")
if d != "Close": if d != "Close":
print d print(d)
else: else:
break break
``` ```
...@@ -44,25 +44,27 @@ import prrt ...@@ -44,25 +44,27 @@ import prrt
host = sys.argv[1] host = sys.argv[1]
port = int(sys.argv[2]) port = int(sys.argv[2])
localport = int(sys.argv[3])
s = prrt.PrrtSocket(port=port) s = prrt.PrrtSocket(port=localport)
s.connect(host, port) s.connect(host, port)
for i in range(10): for i in range(10):
s.send("Packet {}".format(i)) s.send("Packet {}".format(i).encode("utf8"))
s.send("Close") s.send("Close".encode("utf8"))
``` ```
Start the receiver by: Start the receiver by:
```bash ```bash
python receiver.py 5000 python3 receiver.py 5000
``` ```
In a separate terminal, run: In a separate terminal, run:
```bash ```bash
python sender.py 127.0.0.1 5000 python3 sender.py 127.0.0.1 5000 6000
``` ```
This should generate the following output in the receiver console: This should generate the following output in the receiver console:
......
...@@ -89,9 +89,16 @@ local ex_type = Field.new("prrt.type") ...@@ -89,9 +89,16 @@ local ex_type = Field.new("prrt.type")
local function getType() return ex_type()() end local function getType() return ex_type()() end
local function getTypeName() return prrtPacketTypeNames[getType()] end local function getTypeName() return prrtPacketTypeNames[getType()] end
local ex_index = Field.new("prrt.index")
local function getIndex() return ex_index()() end
local ex_data_length = Field.new("prrt.data.length") local ex_data_length = Field.new("prrt.data.length")
local function getDataLength() return ex_data_length()() end local function getDataLength() return ex_data_length()() end
local ex_red_baseseqno = Field.new("prrt.redundancy.baseSequenceNumber")
local function getRedBaseSeqNo() return ex_red_baseseqno()() end
local ex_red_n = Field.new("prrt.redundancy.n") local ex_red_n = Field.new("prrt.redundancy.n")
local function getRedN() return ex_red_n()() end local function getRedN() return ex_red_n()() end
...@@ -109,7 +116,7 @@ local function dissect_data(buffer, pinfo, root) ...@@ -109,7 +116,7 @@ local function dissect_data(buffer, pinfo, root)
tree:add(pf_data_groupRTprop, buffer:range(8,4)) tree:add(pf_data_groupRTprop, buffer:range(8,4))
tree:add(pf_data_packettimeout, buffer:range(12,4)) tree:add(pf_data_packettimeout, buffer:range(12,4))
local label = "DATA Len=" .. getDataLength() local label = "[D] Idx=" .. getIndex() .. " Len=" .. getDataLength()
tree:set_text(label) tree:set_text(label)
pinfo.cols.info:set(label) pinfo.cols.info:set(label)
end end
...@@ -121,7 +128,7 @@ local function dissect_redundancy(buffer, pinfo, root) ...@@ -121,7 +128,7 @@ local function dissect_redundancy(buffer, pinfo, root)
tree:add(pf_red_n, buffer:range(6,1)) tree:add(pf_red_n, buffer:range(6,1))
tree:add(pf_red_k, buffer:range(7,1)) tree:add(pf_red_k, buffer:range(7,1))
local label = "REDUNDANCY n=" .. getRedN() .. " k=" .. getRedK() local label = "[R] Idx=" .. getIndex() .. " b=" .. getRedBaseSeqNo() .. " n=" .. getRedN() .. " k=" .. getRedK()
tree:set_text(label) tree:set_text(label)
pinfo.cols.info:set(label) pinfo.cols.info:set(label)
end end
...@@ -139,7 +146,7 @@ local function dissect_feedback(buffer, pinfo, root) ...@@ -139,7 +146,7 @@ local function dissect_feedback(buffer, pinfo, root)
tree:add(pf_fb_acktype, buffer:range(20,1)) tree:add(pf_fb_acktype, buffer:range(20,1))
tree:add(pf_fb_ackSeqN, buffer:range(21, 2)) tree:add(pf_fb_ackSeqN, buffer:range(21, 2))
local label = "FEEDBACK" local label = "[F]"
tree:set_text(label) tree:set_text(label)
pinfo.cols.info:set(label) pinfo.cols.info:set(label)
end end
......
...@@ -2,9 +2,13 @@ FROM gcc:5 ...@@ -2,9 +2,13 @@ FROM gcc:5
MAINTAINER Andreas Schmidt <schmidt@nt.uni-saarland.de> MAINTAINER Andreas Schmidt <schmidt@nt.uni-saarland.de>
RUN apt-get update \ ENV DEBIAN_FRONTEND noninteractive
&& apt-get upgrade -y \
&& apt-get install -y cmake RUN apt-get update && apt-get install --yes --force-yes \
bc \
cmake \
traceroute \
tshark
COPY CMakeLists.txt /prrt/ COPY CMakeLists.txt /prrt/
COPY prrt /prrt/prrt COPY prrt /prrt/prrt
...@@ -15,8 +19,7 @@ WORKDIR /prrt ...@@ -15,8 +19,7 @@ WORKDIR /prrt
RUN cmake . \ RUN cmake . \
&& make && make
ENV PATH /prrt/bin:$PATH ENV PATH /prrt:$PATH
WORKDIR /prrt/bin
VOLUME /output VOLUME /output
......
FROM gcc:5
MAINTAINER Andreas Schmidt <schmidt@nt.uni-saarland.de>
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install --yes --force-yes \
bc \
cmake \
traceroute \
tshark
COPY CMakeLists.txt /prrt/
COPY prrt /prrt/prrt
COPY tests /prrt/tests
COPY docker/entrypoint.sh /
WORKDIR /prrt
RUN cmake -DTCP=1 . \
&& make
ENV PATH /prrt:$PATH
VOLUME /output
ENTRYPOINT ["/entrypoint.sh"]
FROM gcc:5
MAINTAINER Andreas Schmidt <schmidt@nt.uni-saarland.de>
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install --yes --force-yes \
bc \
cmake \
traceroute \
tshark
COPY CMakeLists.txt /prrt/
COPY prrt /prrt/prrt
COPY tests /prrt/tests
COPY docker/entrypoint.sh /
WORKDIR /prrt
RUN cmake -DCMAKE_BUILD_TYPE=Debug -DXLAP=1 -DDEBUG=1 . \
&& make -i
ENV PATH /prrt:$PATH
VOLUME /output
ENTRYPOINT ["/entrypoint.sh"]
...@@ -5,13 +5,15 @@ dev=eth0 ...@@ -5,13 +5,15 @@ dev=eth0
command=$1 command=$1
shift shift
if [[ "$command" == "sender" || "$command" == "receiver" ]]; then if [[ "$command" == "sender" || "$command" == "receiver" || "$command" == "time-sender" || "$command" == "time-receiver" ]]; then
: :
else else
echo "Command should be either sender or receiver." echo "Command should be either sender or receiver."
exit 0; exit 0;
fi fi
TARGET="127.0.0.1"
OUTPUT="/dev/null"
NETEM=() NETEM=()
PRRT=() PRRT=()
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]
...@@ -19,7 +21,24 @@ do ...@@ -19,7 +21,24 @@ do
key="$1" key="$1"
case $key in case $key in
-t|--target|-p|--port|-r|--rounds) -t|--target)
if [[ "$command" == "sender" || "$command" == "time-sender" ]]; then
PRRT+=("$1 $2")
fi
TARGET=("$2")
shift
shift
;;
-w|--wireshark)
OUTPUT=("$2")
shift
shift
;;
-T|--threadpinning)
PRRT+=("$1")
shift
;;
-p|--port|-r|--rounds|-s|--size|-R|--rcvbuf|-S|--sndbuf|-o|--output|-a|--appdelay)
PRRT+=("$1 $2") PRRT+=("$1 $2")
shift shift
shift shift
...@@ -34,8 +53,31 @@ done ...@@ -34,8 +53,31 @@ done
PRRT_PARAMS="${PRRT[@]}" PRRT_PARAMS="${PRRT[@]}"
NETEM_PARAMS="${NETEM[@]}" NETEM_PARAMS="${NETEM[@]}"
echo "Starting Wireshark."
tshark -i eth0 -w $OUTPUT.pcap &
TSHARK_PID=$!
sleep 5
start=$(date +%s.%N);
echo "Checking reachability of $TARGET."
until ping -c1 $TARGET &>/dev/null; sleep 1; do :; done
dur=$(echo "$(date +%s.%N) - $start" | bc);
printf "Reachable after %.6f seconds\n" $dur
traceroute $TARGET > $OUTPUT.tr
echo "Traceroute done."
if [[ "$command" == "sender" || "$command" == "time-sender" ]]; then
echo "Delaying sender start."
else
echo "Delaying receiver start."
fi
echo "Running PRRT with command: \"$command $PRRT_PARAMS\" and link parameters: \"$NETEM_PARAMS\"" echo "Running PRRT with command: \"$command $PRRT_PARAMS\" and link parameters: \"$NETEM_PARAMS\""
tc qdisc add dev $dev root netem $NETEM_PARAMS tc qdisc add dev $dev root netem $NETEM_PARAMS
/prrt/$command $PRRT_PARAMS -o /output/log.csv /prrt/$command $PRRT_PARAMS
echo "Done."
tc qdisc del dev $dev root tc qdisc del dev $dev root
kill $TSHARK_PID
...@@ -10,14 +10,26 @@ if (XLAP) ...@@ -10,14 +10,26 @@ if (XLAP)
add_definitions(-DXLAP) add_definitions(-DXLAP)
endif() endif()
option (TCP "Set time protocol to TCP.")
if (TCP)
add_definitions(-DTCP)
endif()
add_subdirectory(proto) add_subdirectory(proto)
add_subdirectory(util) add_subdirectory(util)
add_executable(sender sender.c) add_executable(sender sender.c)
add_executable(receiver receiver.c) add_executable(receiver receiver.c)
add_executable(refcount refcount.c) add_executable(time-sender time-sender.c)
add_executable(time-receiver time-receiver.c)
target_link_libraries(sender LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(sender LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(receiver LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(receiver LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(time-sender LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(time-receiver LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT})
add_executable(refcount refcount.c)
target_link_libraries(refcount LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(refcount LINK_PUBLIC PRRT UTIL ${CMAKE_THREAD_LIBS_INIT})
...@@ -119,11 +119,13 @@ cdef extern from "proto/socket.h": ...@@ -119,11 +119,13 @@ cdef extern from "proto/socket.h":
ctypedef prrtSocket PrrtSocket ctypedef prrtSocket PrrtSocket
cdef PrrtSocket* PrrtSocket_create(const uint32_t mtu, const uint32_t target_delay) cdef PrrtSocket* PrrtSocket_create(const uint32_t maximum_payload_size, const uint32_t target_delay)
bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port) bint PrrtSocket_bind(PrrtSocket *sock_ptr, const_char *ipAddress, const uint16_t port)
int PrrtSocket_close(const PrrtSocket *sock_ptr) int PrrtSocket_close(const PrrtSocket *sock_ptr)
int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port) int PrrtSocket_connect(PrrtSocket *sock_ptr, const_char *host, const uint16_t port)
int PrrtSocket_send(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data_len) int PrrtSocket_send_sync(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data_len)
int PrrtSocket_send_async(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data_len)
int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr, sockaddr* addr) nogil int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr, sockaddr* addr) nogil
int32_t PrrtSocket_receive_asap(PrrtSocket *s, void *buf_ptr, sockaddr* addr) nogil int32_t PrrtSocket_receive_asap(PrrtSocket *s, void *buf_ptr, sockaddr* addr) nogil
...@@ -144,11 +146,23 @@ cdef extern from "proto/socket.h": ...@@ -144,11 +146,23 @@ cdef extern from "proto/socket.h":
uint32_t PrrtSocket_get_rtprop_fwd(PrrtSocket *socket) uint32_t PrrtSocket_get_rtprop_fwd(PrrtSocket *socket)
float PrrtSocket_get_plr_fwd(PrrtSocket *socket) float PrrtSocket_get_plr_fwd(PrrtSocket *socket)
uint32_t PrrtSocket_get_delivery_rate_fwd(PrrtSocket *socket) uint32_t PrrtSocket_get_delivery_rate_fwd(PrrtSocket *socket)
uint32_t PrrtSocket_get_btlbw_fwd(PrrtSocket *s); uint32_t PrrtSocket_get_btlbw_fwd(PrrtSocket *s);
uint32_t PrrtSocket_get_btlbw_back(PrrtSocket *s); uint32_t PrrtSocket_get_btlbw_back(PrrtSocket *s);
bint PrrtSocket_get_app_limited(PrrtSocket *socket) uint32_t PrrtSocket_get_bbr_state(PrrtSocket *s)
uint64_t PrrtSocket_get_full_bw(PrrtSocket *s)
bint PrrtSocket_get_filled_pipe(PrrtSocket *s)
uint32_t PrrtSocket_get_cycle_index(PrrtSocket *s)
float PrrtSocket_get_pacing_gain(PrrtSocket *s)
uint32_t PrrtSocket_get_cwnd(PrrtSocket *s)
uint32_t PrrtSocket_get_inflight(PrrtSocket *s)
uint32_t PrrtSocket_get_pacing_rate(PrrtSocket *s)
uint32_t PrrtSocket_get_send_quantum(PrrtSocket *s)
uint32_t PrrtSocket_get_pipe(PrrtSocket *s)
uint32_t PrrtSocket_get_delivered(PrrtSocket *s)
bint PrrtSocket_get_bbr_round_start(PrrtSocket *s)
uint32_t PrrtSocket_get_bbr_app_limited(PrrtSocket *socket)
bint PrrtSocket_get_bbr_is_app_limited(PrrtSocket *socket)
bint PrrtSocket_enable_thread_pinning(PrrtSocket *socket) bint PrrtSocket_enable_thread_pinning(PrrtSocket *socket)
cdef extern from "proto/stores/packetDeliveryStore.h": cdef extern from "proto/stores/packetDeliveryStore.h":
......
set (PRRT_SOURCES ../defines.h set (PRRT_SOURCES ../defines.h
types/block.c types/block.h bbr.c bbr.h
types/channelStateInformation.c types/channelStateInformation.h
clock.c clock.h clock.c clock.h
types/codingParams.c types/codingParams.h
receiver.c receiver.h receiver.c receiver.h
socket.c socket.h socket.c socket.h
types/applicationConstraints.c types/applicationConstraints.h timer.c timer.h
processes/dataReceiver.c processes/dataReceiver.h processes/dataReceiver.c processes/dataReceiver.h
processes/dataTransmitter.c processes/dataTransmitter.h processes/dataTransmitter.c processes/dataTransmitter.h
stores/dataPacketStore.c stores/dataPacketStore.h stores/dataPacketStore.c stores/dataPacketStore.h
...@@ -15,10 +13,14 @@ set (PRRT_SOURCES ../defines.h ...@@ -15,10 +13,14 @@ set (PRRT_SOURCES ../defines.h
stores/packetDeliveryStore.c stores/packetDeliveryStore.h stores/packetDeliveryStore.c stores/packetDeliveryStore.h
stores/receptionTable.c stores/receptionTable.h stores/receptionTable.c stores/receptionTable.h
stores/repairBlockStore.c stores/repairBlockStore.h stores/repairBlockStore.c stores/repairBlockStore.h
types/packetTimeout.c types/packetTimeout.h types/applicationConstraints.c types/applicationConstraints.h
types/block.c types/block.h
types/codingParams.c types/codingParams.h
types/channelStateInformation.c types/channelStateInformation.h
types/lossStatistics.c types/lossStatistics.h types/lossStatistics.c types/lossStatistics.h
types/packet.c types/packet.h types/packet.c types/packet.h
vdmcode/block_code.c vdmcode/block_code.h) types/packetTimeout.c types/packetTimeout.h
vdmcode/block_code.c vdmcode/block_code.h types/packetTracking.c types/packetTracking.h types/rateSample.c types/rateSample.h)
if (XLAP) if (XLAP)
set(PRRT_SOURCES ${PRRT_SOURCES} ../xlap/xlap.c ../xlap/xlap.h) set(PRRT_SOURCES ${PRRT_SOURCES} ../xlap/xlap.c ../xlap/xlap.h)
......
#include "bbr.h"
#include "../util/dbg.h"
#include "../util/common.h"
#include "receiver.h"
#include <math.h>
prrtByteCount_t BBR_Inflight(BBR* bbr, double gain)
{
if (bbr->rtprop == RTprop_Inf)
return bbr->initial_cwnd; /* no valid RTT samples yet */
uint32_t quanta = bbr->mps;
uint32_t estimated_bdp = (uint32_t) round((((double)bbr->bw) * bbr->rtprop) / (1000 * 1000));
return (uint32_t)(gain * estimated_bdp + quanta);
}
void BBR_EnterStartup(BBR* bbr)
{
bbr->state = STARTUP;
bbr->pacing_gain = BBRHighGain;
bbr->cwnd_gain = BBRHighGain;
}
void BBR_UpdateBtlBw(BBR* bbr, PrrtRateSample* rs, PrrtPacketTracking* tracking)
{
if (tracking->delivered >= bbr->next_round_delivered) {
bbr->next_round_delivered = tracking->delivered;
bbr->round_count++;
bbr->round_start = true;
} else {
bbr->round_start = false;
}
uint32_t delivery_rate_Bps = (uint32_t)((float) rs->delivery_rate);
if ((delivery_rate_Bps >= bbr->bw || !rs->is_app_limited) && delivery_rate_Bps != 0) {
bbr->bw = (uint32_t)WindowedFilter_push(bbr->btlBwFilter, delivery_rate_Bps);
debug(DEBUG_BBR, "Current BtlBw: %u, RS delivery rate: %u", bbr->bw, delivery_rate_Bps);
}
}
void BBR_CheckFullPipe(BBR* bbr, PrrtRateSample* rs)
{
if (bbr->filled_pipe || !bbr->round_start || rs->is_app_limited)
return; // no need to check for a full pipe now
if (bbr->bw >= bbr->full_bw * PROBE_GAIN) { // BBR.BtlBw still growing?
bbr->full_bw = bbr->bw; // record new baseline level
bbr->full_bw_count = 0;
return;
}
bbr->full_bw_count++; // another round w/o much growth
if (bbr->full_bw_count >= 3)
bbr->filled_pipe = true;
}
bool BBR_IsNextCyclePhase(BBR* bbr, prrtByteCount_t bytes_lost, prrtByteCount_t prior_inflight)
{
bool is_full_length = (PrrtClock_get_current_time_us() - bbr->cycle_stamp) > bbr->rtprop;
if (bbr->pacing_gain == 1)
return is_full_length;
if (bbr->pacing_gain > 1)
return is_full_length && (bytes_lost > 0 || prior_inflight >= BBR_Inflight(bbr, bbr->pacing_gain));
bool is_max_length = (PrrtClock_get_current_time_us() - bbr->cycle_stamp) > 4 * bbr->rtprop;
return is_max_length || (prior_inflight <= BBR_Inflight(bbr, 1.0));
}
void BBR_AdvanceCyclePhase(BBR* bbr)
{
bbr->cycle_stamp = PrrtClock_get_current_time_us();
bbr->cycle_index = (uint8_t )((bbr->cycle_index + 1) % BBRGainCycleLen);
float pacing_gain_cycle[BBRGainCycleLen] = {PROBE_GAIN, DRAIN_GAIN, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
bbr->pacing_gain = pacing_gain_cycle[bbr->cycle_index];
debug(DEBUG_BBR, "Advanced cycle with gain: %f", bbr->pacing_gain);
}
void BBR_CheckCyclePhase(BBR* bbr, prrtByteCount_t bytes_lost, prrtByteCount_t prior_inflight) {
if (bbr->state == PROBE_BW && BBR_IsNextCyclePhase(bbr, bytes_lost, prior_inflight))
BBR_AdvanceCyclePhase(bbr);
}
void BBR_EnterProbeBW(BBR* bbr)
{
bbr->state = PROBE_BW;
bbr->pacing_gain = 1;
bbr->cwnd_gain = 2;
bbr->cycle_index = (uint8_t)(BBRGainCycleLen - 1 - (random() % 7));
BBR_AdvanceCyclePhase(bbr);
}
void BBR_CheckDrain(BBR* bbr, prrtByteCount_t bytes_inflight)
{
if (bbr->state == STARTUP && bbr->filled_pipe) {
//Drain
bbr->state = DRAIN;
bbr->pacing_gain = 1 / BBRHighGain; // pace slowly
bbr->cwnd_gain = BBRHighGain; // maintain cwnd
}
if (bbr->state == DRAIN && bytes_inflight <= BBR_Inflight(bbr, 1.0))
BBR_EnterProbeBW(bbr); // we estimate queue is drained
}
void BBR_ExitProbeRTT(BBR* bbr)
{
if (bbr->filled_pipe)
BBR_EnterProbeBW(bbr);
else
BBR_EnterStartup(bbr);
}
uint32_t BBR_SaveCwnd(BBR* bbr)
{
if (!bbr->is_loss_recovery && bbr->state != PROBE_RTT)
return bbr->cwnd;
return MAX(bbr->prior_cwnd ,bbr->cwnd);
}
void BBR_RestoreCwnd(BBR* bbr)
{
bbr->cwnd = MAX(bbr->cwnd, bbr->prior_cwnd);
}
void BBR_UpdateRTprop(BBR* bbr, prrtTimedelta_t rtt)
{
bbr->rtprop_expired = PrrtClock_get_current_time_us() > (bbr->rtprop_stamp + RTpropFilterLen);
if (rtt >= 0 && (rtt <= bbr->rtprop || bbr->rtprop_expired)) {
bbr->rtprop = rtt;
bbr->rtprop_stamp = PrrtClock_get_current_time_us();
}
}
void BBR_EnterProbeRTT(BBR *bbr) {
bbr->state = PROBE_RTT;
bbr->pacing_gain = 1;
bbr->cwnd_gain = 1;
}
void BBR_HandleProbeRTT(BBR *bbr, PrrtPacketTracking *tracking) {
tracking->app_limited = (tracking->delivered + tracking->pipe) ? : 1;
/* Ignore low rate samples during ProbeRTT: */
prrtTimestamp_t now = PrrtClock_get_current_time_us();
if (bbr->probe_rtt_done_stamp == 0 && tracking->pipe <= bbr->min_pipe_cwnd) {
bbr->probe_rtt_done_stamp = now + ProbeRTTDuration;
bbr->probe_rtt_round_done = false;
bbr->next_round_delivered = tracking->delivered;
} else if (bbr->probe_rtt_done_stamp != 0) {
if (bbr->round_start) {
bbr->probe_rtt_round_done = true;
}
if (bbr->probe_rtt_round_done && (now > bbr->probe_rtt_done_stamp)) {
bbr->rtprop_stamp = now;
BBR_RestoreCwnd(bbr);
BBR_ExitProbeRTT(bbr);
}
}
}
void BBR_CheckProbeRTT(BBR *bbr, PrrtPacketTracking *tracking) {
if (bbr->state != PROBE_RTT && bbr->rtprop_expired && !bbr->idle_restart) {
BBR_EnterProbeRTT(bbr);
BBR_SaveCwnd(bbr);
bbr->probe_rtt_done_stamp = 0;
}
if (bbr->state == PROBE_RTT) {
BBR_HandleProbeRTT(bbr, tracking);
}
bbr->idle_restart = false;
}
void BBR_UpdateModelAndState(BBR *bbr, PrrtRateSample *rs, PrrtPacketTracking *packetTracking, prrtTimedelta_t rtt)
{
BBR_UpdateBtlBw(bbr, rs, packetTracking);
BBR_CheckCyclePhase(bbr, packetTracking->bytes_lost, packetTracking->prior_inflight);
BBR_CheckFullPipe(bbr, rs);
BBR_CheckDrain(bbr, packetTracking->pipe);
BBR_UpdateRTprop(bbr, rtt);
BBR_CheckProbeRTT(bbr, packetTracking);
}
void BBR_UpdateTargetCwnd(BBR* bbr)
{
bbr->target_cwnd = BBR_Inflight(bbr, bbr->cwnd_gain);
}
void BBR_ModulateCwndForProbeRTT(BBR* bbr)
{
if (bbr->state == PROBE_RTT)
bbr->cwnd = MIN(bbr->cwnd, bbr->min_pipe_cwnd);
}
void BBR_ModulateCwndForRecovery(BBR* bbr, prrtByteCount_t bytes_lost, prrtByteCount_t pipe, prrtByteCount_t delivered)
{
if (bytes_lost > 0) {
if (bbr->cwnd > bytes_lost) {
bbr->cwnd = MAX(bbr->cwnd - bytes_lost, bbr->mps);
} else {
bbr->cwnd = bbr->mps;
}
}
if (bbr->packet_conservation)
bbr->cwnd = MAX(bbr->cwnd, pipe + delivered);
}
void BBR_SetCwnd(BBR* bbr, PrrtPacketTracking* packetTracking)
{
BBR_UpdateTargetCwnd(bbr);
BBR_ModulateCwndForRecovery(bbr, packetTracking->bytes_lost, packetTracking->pipe, packetTracking->delivered);
if (!bbr->packet_conservation) {
if (bbr->filled_pipe)
bbr->cwnd = MIN(bbr->cwnd + packetTracking->delivered, bbr->target_cwnd);
else if (bbr->cwnd < bbr->target_cwnd || packetTracking->delivered < bbr->initial_cwnd)
bbr->cwnd = bbr->cwnd + packetTracking->delivered;
bbr->cwnd = MAX(bbr->cwnd, bbr->min_pipe_cwnd);
}
BBR_ModulateCwndForProbeRTT(bbr);
debug(DEBUG_BBR, "New cwnd: %u, State: %u", bbr->cwnd, bbr->state);
}
void BBR_SetPacingRateWithGain(BBR* bbr, double pacing_gain)
{
double rate = (pacing_gain * ((double)bbr->bw));
debug(DEBUG_BBR, "Current rate: %f, Pacing gain: %f, BtlBw: %u, Calc Rate: %f, Filled pipe: %u", bbr->pacing_rate,
pacing_gain, bbr->bw, rate, bbr->filled_pipe);
if (rate != 0 && (bbr->filled_pipe || rate > bbr->pacing_rate))
bbr->pacing_rate = rate;
}
void BBR_SetPacingRate(BBR* bbr)
{
BBR_SetPacingRateWithGain(bbr, bbr->pacing_gain);
}
void BBR_SetSendQuantum(BBR* bbr) {
if(bbr->pacing_rate < 150000) { // 1.2Mbps = 0.15 MBps = 150000 Bps
bbr->send_quantum = 1 * bbr->mps;
} else if (bbr->pacing_rate < 3000000) { // 24 Mbps = 20 * 1.2Mbps = 3000000
bbr->send_quantum = 2 * bbr->mps;
} else {
bbr->send_quantum = MIN((prrtByteCount_t) round((double) bbr->pacing_rate / 1000), 64000);
}
}
void BBR_OnACK(BBR* bbr, PrrtChannelStateInformation* csi, PrrtRateSample* rs, PrrtPacketTracking* packetTracking, prrtTimedelta_t rtt)
{
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
BBR_UpdateModelAndState(bbr, rs, packetTracking, rtt);
BBR_SetPacingRate(bbr);
BBR_SetSendQuantum(bbr);
BBR_SetCwnd(bbr, packetTracking);
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return;
error:
PERROR("BBR_OnACK failed.")
}
void BBR_OnSpuriousLoss(BBR *bbr, PrrtPacketTracking *tracking) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
if(!bbr->is_loss_recovery) {
bbr->is_loss_recovery = true;
bbr->loss_recovery_stamp = PrrtClock_get_current_time_us();
bbr->prior_cwnd = BBR_SaveCwnd(bbr);
bbr->cwnd = tracking->pipe + MAX(tracking->delivered, 1);
bbr->packet_conservation = true;
} else if (PrrtClock_get_current_time_us() > bbr->loss_recovery_stamp + bbr->rtprop){
bbr->packet_conservation = false;
}
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return;
error:
PERROR("BBR_OnACK failed.")
}
void BBR_OnRTOLoss(BBR *bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
if(!bbr->is_loss_recovery) {
bbr->is_loss_recovery = true;
bbr->prior_cwnd = BBR_SaveCwnd(bbr);
bbr->cwnd = bbr->mps;
}
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return;
error:
PERROR("BBR_OnACK failed.")
}
void BBR_OnLossExit(BBR *bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
if(bbr->is_loss_recovery) {
bbr->is_loss_recovery = false;
bbr->packet_conservation = false;
BBR_RestoreCwnd(bbr);
}
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return;
error:
PERROR("BBR_OnACK failed.")
}
BBR* BBR_Init(prrtByteCount_t maximum_payload_size)
{
BBR* bbr = calloc(1, sizeof(BBR));
check_mem(bbr);
pthread_mutexattr_t attr;
check(pthread_mutexattr_init(&attr) == EXIT_SUCCESS, "Mutex attr init failed.");
check(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) == EXIT_SUCCESS, "Setting type failed.");
check(pthread_mutex_init(&bbr->lock, &attr) == 0, "lock init failed.");
bbr->mps = maximum_payload_size;
bbr->min_pipe_cwnd = 4 * maximum_payload_size;
bbr->initial_cwnd = 4 * maximum_payload_size;
bbr->has_seen_rtt = false;
bbr->btlBwFilter = WindowedFilter_create(true, 10);
bbr->rtprop = RTprop_Inf;
bbr->rtprop_stamp = PrrtClock_get_current_time_us();
bbr->probe_rtt_done_stamp = 0;
bbr->probe_rtt_round_done = false;
bbr->packet_conservation = false;
bbr->prior_cwnd = 0;
bbr->cwnd = bbr->initial_cwnd;
bbr->idle_restart = false;
bbr->is_loss_recovery = false;
//Init round counting
bbr->next_round_delivered = 0;
bbr->round_start = false;
bbr->round_count = 0;
//Init full pipe
bbr->filled_pipe = false;
bbr->full_bw = 0;
bbr->full_bw_count = 0;
//Init pacing rate
double nominal_bandwidth = bbr->initial_cwnd / (bbr->has_seen_rtt ? bbr->rtprop : 1000);
bbr->pacing_rate = bbr->pacing_gain * nominal_bandwidth;
BBR_EnterStartup(bbr);
return bbr;
error:
PERROR("Failed to init BBR%s.", "");
return NULL;
}
void BBR_destroy(BBR* bbr)
{
WindowedFilter_destroy(bbr->btlBwFilter);
check(pthread_mutex_destroy(&bbr->lock) == 0, "lock destroy failed.");
free(bbr);
return;
error:
PERROR("BBR_destroy failed%s.", "");
}
double BBR_getPacingRate(BBR* bbr)
{
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
double res = bbr->pacing_rate;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getPacingRate failed.")
return 0;
}
prrtByteCount_t BBR_getCwnd(BBR* bbr)
{
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
prrtByteCount_t res = bbr->cwnd;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getCwnd failed.")
return 0;
}
prrtDeliveryRate_t BBR_getBtlBw(BBR* bbr)
{
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
prrtDeliveryRate_t res = bbr->bw;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getBtlBw failed.")
return 0;
}
uint32_t BBR_getRTProp(BBR* bbr)
{
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
uint32_t res = bbr->rtprop;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getRTProp failed.")
return 0;
}
uint32_t BBR_getState(BBR* bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
uint32_t res = bbr->state;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getState failed.")
return 0;
}
uint32_t BBR_getCycleIndex(BBR* bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
uint32_t res = bbr->cycle_index;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getCycleIndex failed.")
return 0;
}
double BBR_getPacingGain(BBR* bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
double res = bbr->pacing_gain;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getPacingGain failed.")
return 0;
}
bool BBR_getFilledPipe(BBR* bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
bool res = bbr->filled_pipe;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getFilledPipe failed.")
return 0;
}
bool BBR_getRoundStart(BBR* bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
bool res = bbr->round_start;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getRoundStart failed.")
return 0;
}
prrtByteCount_t BBR_getFullBw(BBR* bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
prrtByteCount_t res = bbr->full_bw;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getInflight failed.")
return 0;
}
prrtByteCount_t BBR_getInflight(BBR* bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
prrtByteCount_t res = BBR_Inflight(bbr, bbr->pacing_gain);
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getInflight failed.")
return 0;
}
prrtByteCount_t BBR_getSendQuantum(BBR* bbr) {
check(pthread_mutex_lock(&bbr->lock) == 0, "Lock failed.");
prrtByteCount_t res = bbr->send_quantum;
check(pthread_mutex_unlock(&bbr->lock) == 0, "Unlock failed.");
return res;
error:
PERROR("BBR_getSendQuantum failed.")
return 0;
}
\ No newline at end of file
#ifndef PRRT_BBR_H
#define PRRT_BBR_H
#include <stdint.h>
#include "stdbool.h"
#include "types/packet.h"
#include "clock.h"
#include "types/channelStateInformation.h"
#include "types/packetTracking.h"
#include "types/rateSample.h"
#include "../util/windowedFilter.h"
#define PROBE_GAIN 1.25
#define DRAIN_GAIN 0.75
#define RTpropFilterLen 10000000 //10s
#define BBRHighGain ((((float)2885) / 1000) + 1)
#define BBRGainCycleLen 8
#define ProbeRTTDuration 200000 //200ms
#define RTprop_Inf UINT32_MAX
enum bbr_state {
STARTUP,
DRAIN,
PROBE_BW,
PROBE_RTT
};
typedef struct bbr {
pthread_mutex_t lock;
prrtByteCount_t mps;
prrtByteCount_t min_pipe_cwnd;
prrtByteCount_t initial_cwnd;
prrtTimedelta_t rtprop;
prrtTimestamp_t rtprop_stamp;
prrtTimestamp_t probe_rtt_done_stamp;
bool probe_rtt_round_done;
bool packet_conservation;
prrtByteCount_t prior_cwnd;
prrtByteCount_t cwnd;
prrtByteCount_t target_cwnd;
bool idle_restart;
enum bbr_state state;
double pacing_gain;
float cwnd_gain;
bool filled_pipe;
prrtByteCount_t full_bw;
uint32_t full_bw_count;
double pacing_rate;
bool has_seen_rtt;
uint32_t next_round_delivered;
bool round_start;
uint32_t round_count;
uint32_t next_rtt_delivered;
uint32_t rtt_count;
bool rtprop_expired;
bool is_loss_recovery;
prrtTimestamp_t loss_recovery_stamp;
prrtTimestamp_t cycle_stamp;
uint8_t cycle_index;
float* pacing_gain_cycle;
prrtByteCount_t send_quantum;
prrtDeliveryRate_t bw;
WindowedFilter* btlBwFilter;
} BBR;
BBR* BBR_Init(prrtByteCount_t maximum_payload_size);
void BBR_OnACK(BBR* bbr, PrrtChannelStateInformation* csi, PrrtRateSample* rs, PrrtPacketTracking* packetTracking, prrtTimedelta_t rtt);
void BBR_OnSpuriousLoss(BBR *bbr, PrrtPacketTracking *tracking);
void BBR_OnRTOLoss(BBR *bbr);
void BBR_OnLossExit(BBR *bbr);
void BBR_destroy(BBR* bbr);
double BBR_getPacingRate(BBR* bbr);
prrtByteCount_t BBR_getCwnd(BBR* bbr);
prrtDeliveryRate_t BBR_getBtlBw(BBR* bbr);
uint32_t BBR_getState(BBR* bbr);
prrtByteCount_t BBR_getFullBw(BBR* bbr);
double BBR_getPacingGain(BBR* bbr);
uint32_t BBR_getCycleIndex(BBR* bbr);
bool BBR_getFilledPipe(BBR* bbr);
uint32_t BBR_getRTProp(BBR* bbr);
prrtByteCount_t BBR_getInflight(BBR* bbr);
prrtByteCount_t BBR_getSendQuantum(BBR* bbr);
bool BBR_getRoundStart(BBR* bbr);
#endif //PRRT_BBR_H
...@@ -4,24 +4,27 @@ ...@@ -4,24 +4,27 @@
#include "../../defines.h" #include "../../defines.h"
#include "../../util/dbg.h" #include "../../util/dbg.h"
#include "../../util/common.h" #include "../../util/common.h"
#include "../../util/time.h"
#include "../types/lossStatistics.h" #include "../types/lossStatistics.h"
#include "../types/block.h" #include "../types/block.h"
#include "../clock.h" #include "../clock.h"
#include "../socket.h" #include "../socket.h"
#include "dataReceiver.h" #include "dataReceiver.h"
static void retrieve_data_blocks(PrrtSocket *sock_ptr, static void retrieve_data_packets_for_block(PrrtSocket *sock_ptr,
prrtSequenceNumber_t base_seqno, prrtSequenceNumber_t base_seqno,
uint8_t k, uint8_t k,
const PrrtBlock *block) { const PrrtBlock *block) {
List *res = List_create(); List *res = List_create();
prrtSequenceNumber_t last_seqno = (prrtSequenceNumber_t) (base_seqno + k - 1);
debug(DEBUG_BLOCK, "Size: %d", PrrtDataPacketStore_size(sock_ptr->dataPacketStore));
PrrtDataPacketStore_remove_range(sock_ptr->dataPacketStore, res, base_seqno, PrrtDataPacketStore_remove_range(sock_ptr->dataPacketStore, res, base_seqno,
(prrtSequenceNumber_t) (base_seqno + k - 1)); last_seqno);
debug(DEBUG_BLOCK, "Retrieve %d packets in range: %u-%u.", List_count(res), base_seqno, last_seqno);
LIST_FOREACH(res, first, next, cur) { LIST_FOREACH(res, first, next, cur) {
PrrtPacket *packetPtr = cur->value; PrrtPacket *packet = cur->value;
check(PrrtBlock_insert_data_packet((PrrtBlock *) block, packetPtr), "Insert failed!") check(PrrtBlock_insert_data_packet((PrrtBlock *) block, packet), "Insert failed!")
} }
List_destroy(res); List_destroy(res);
return; return;
...@@ -32,18 +35,23 @@ static void retrieve_data_blocks(PrrtSocket *sock_ptr, ...@@ -32,18 +35,23 @@ static void retrieve_data_blocks(PrrtSocket *sock_ptr,
static void decode_block(PrrtSocket *sock_ptr, PrrtBlock *block) { static void decode_block(PrrtSocket *sock_ptr, PrrtBlock *block) {
if (block != NULL && PrrtBlock_decode_ready(block)) { if (block != NULL && PrrtBlock_decode_ready(block)) {
check(PrrtBlock_decode(block), "Decoding failed"); bool data_relevant = PrrtDeliveredPacketTable_test_is_block_relevant(sock_ptr->deliveredPacketTable,
block->baseSequenceNumber,
while (List_count(block->dataPackets) > 0) { block->codingParams->n);
PrrtPacket *pkt = List_shift(block->dataPackets); if (data_relevant) {
if (PrrtDeliveredPacketTable_test_set_is_number_relevant(sock_ptr->deliveredPacketTable, check(PrrtBlock_decode(block), "Decoding failed");
pkt->sequenceNumber)) {
PrrtPacketDeliveryStore_insert(sock_ptr->packetDeliveryStore, pkt); // TODO add a method for this (PrrtBlock_has_next_data)
} else { while (block->nextDataPacket < block->dataPacketCount) {
PrrtPacket_destroy(pkt); PrrtPacket *pkt = PrrtBlock_get_next_data(block);
if (PrrtDeliveredPacketTable_test_set_is_number_relevant(sock_ptr->deliveredPacketTable,
pkt->sequenceNumber)) {
PrrtPacketDeliveryStore_insert(sock_ptr->packetDeliveryStore, pkt);
} else {
PrrtPacket_destroy(pkt);
}
} }
} }
PrrtRepairBlockStore_delete(sock_ptr->repairBlockStore, block->baseSequenceNumber); PrrtRepairBlockStore_delete(sock_ptr->repairBlockStore, block->baseSequenceNumber);
PrrtBlock_destroy(block); PrrtBlock_destroy(block);
} }
...@@ -67,7 +75,6 @@ static bool send_feedback(PrrtSocket *sock_ptr, ...@@ -67,7 +75,6 @@ static bool send_feedback(PrrtSocket *sock_ptr,
kind = ts_redundancy_packet; kind = ts_redundancy_packet;
} }
debug(DEBUG_FEEDBACK, "Send feedback %d %d", type, seqno);
XlapTimeStampCycle(sock_ptr, kind, seqno, SendFeedbackStart); XlapTimeStampCycle(sock_ptr, kind, seqno, SendFeedbackStart);
prrtFeedback_t feedback = { prrtFeedback_t feedback = {
...@@ -107,8 +114,10 @@ static bool send_feedback(PrrtSocket *sock_ptr, ...@@ -107,8 +114,10 @@ static bool send_feedback(PrrtSocket *sock_ptr,
check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, feedback_pkt_ptr), "Buffer for encoding feedback is too small"); check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, feedback_pkt_ptr), "Buffer for encoding feedback is too small");
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
check(sendto(sock_ptr->socketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) == check(sendto(sock_ptr->socketFd, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) ==
length, "Sending feedback failed."); length, "Sending feedback failed.");
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
free(buf); free(buf);
PrrtPacket_destroy(feedback_pkt_ptr); PrrtPacket_destroy(feedback_pkt_ptr);
...@@ -122,16 +131,12 @@ static bool send_feedback(PrrtSocket *sock_ptr, ...@@ -122,16 +131,12 @@ static bool send_feedback(PrrtSocket *sock_ptr,
return false; return false;
} }
static bool is_timeout(prrtTimestamp_t now, prrtTimestamp_t to) {
/* TODO: implement */
return false;
}
static void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { static void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
PrrtPacketDataPayload *payload = packet->payload; PrrtPacketDataPayload *payload = packet->payload;
prrtTimestamp_t sentTimestamp = payload->timestamp; prrtTimestamp_t sentTimestamp = payload->timestamp;
sock_ptr->lastSentTimestamp = sentTimestamp; sock_ptr->lastSentTimestamp = sentTimestamp;
PrrtClock_update(&sock_ptr->clock, sentTimestamp, payload->groupRTprop_us); PrrtClock_update(&sock_ptr->clock, sentTimestamp, payload->groupRTprop_us);
debug(DEBUG_DATARECEIVER, "Timeout: %lu", payload->packetTimeout_us);
PrrtPacketTimeout *packetTimeout = PrrtPacketTimeout_create(packet); PrrtPacketTimeout *packetTimeout = PrrtPacketTimeout_create(packet);
check(PrrtPacketTimeoutTable_insert(sock_ptr->packetTimeoutTable, packetTimeout), "Could not insert data packet."); check(PrrtPacketTimeoutTable_insert(sock_ptr->packetTimeoutTable, packetTimeout), "Could not insert data packet.");
...@@ -139,18 +144,24 @@ static void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { ...@@ -139,18 +144,24 @@ static void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
prrtSequenceNumber_t seqno = packet->sequenceNumber; prrtSequenceNumber_t seqno = packet->sequenceNumber;
PrrtReceptionTable_mark_received(sock_ptr->dataReceptionTable, seqno); PrrtReceptionTable_mark_received(sock_ptr->dataReceptionTable, seqno);
prrtTimestamp_t now = PrrtClock_get_prrt_time_us(&sock_ptr->clock); prrtTimestamp_t now = PrrtClock_get_current_time_us();
if (is_timeout(now, payload->packetTimeout_us)) { if (PrrtTimestamp_cmp(now, payload->packetTimeout_us) > 0) {
debug(DEBUG_DATARECEIVER, "Timeout data packet %u (%lu > %lu)", seqno, (unsigned long) now,
(unsigned long) payload->packetTimeout_us);
PrrtDeliveredPacketTable_test_set_is_number_relevant(sock_ptr->deliveredPacketTable, packet->sequenceNumber); PrrtDeliveredPacketTable_test_set_is_number_relevant(sock_ptr->deliveredPacketTable, packet->sequenceNumber);
PrrtPacket_destroy(packet); PrrtPacket_destroy(packet);
debug(DEBUG_RECEIVER, "timeout data packet %u (%lu > %lu)", seqno, (unsigned long) now,
(unsigned long) payload->packetTimeout_us);
} else if (!PrrtDeliveredPacketTable_test_set_is_number_relevant(sock_ptr->deliveredPacketTable, } else if (!PrrtDeliveredPacketTable_test_set_is_number_relevant(sock_ptr->deliveredPacketTable,
packet->sequenceNumber)) { packet->sequenceNumber)) {
debug(DEBUG_DATARECEIVER, "Not relevant: %u", seqno);
PrrtPacket_destroy(packet); PrrtPacket_destroy(packet);
} else { } else {
PrrtChannelStateInformation_update_delivery_rate(sock_ptr->senderChannelStateInformation, payload->btlbw);
prrtSequenceNumber_t baseSequenceNumber = packet->sequenceNumber - packet->index; prrtSequenceNumber_t baseSequenceNumber = packet->sequenceNumber - packet->index;
// forward to application layer
debug(DEBUG_DATARECEIVER, "Forward: %u", seqno);
PrrtPacketDeliveryStore_insert(sock_ptr->packetDeliveryStore, packet);
PrrtPacket *reference = PrrtPacket_copy(packet); PrrtPacket *reference = PrrtPacket_copy(packet);
// forward to application layer // forward to application layer
...@@ -159,18 +170,21 @@ static void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { ...@@ -159,18 +170,21 @@ static void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
PrrtBlock *block = PrrtRepairBlockStore_get_block(sock_ptr->repairBlockStore, baseSequenceNumber); PrrtBlock *block = PrrtRepairBlockStore_get_block(sock_ptr->repairBlockStore, baseSequenceNumber);
if (block != NULL) { if (block != NULL) {
check(PrrtBlock_insert_data_packet(block, reference), "Inserting failed: %d, %d", baseSequenceNumber, if(PrrtBlock_insert_data_packet(block, reference)) {
seqno); decode_block(sock_ptr, block);
decode_block(sock_ptr, block); } else {
PrrtPacket_destroy(reference);
}
} else { } else {
debug(DEBUG_DATARECEIVER, "Inserting data packet %d for later.", reference->sequenceNumber);
if (PrrtDataStore_insert(sock_ptr->dataPacketStore, reference) == false) { if (PrrtDataStore_insert(sock_ptr->dataPacketStore, reference) == false) {
debug(DEBUG_DATARECEIVER, "Failed to insert %d.", reference->sequenceNumber);
PrrtPacket_destroy(reference); PrrtPacket_destroy(reference);
} else {
debug(DEBUG_DATARECEIVER, "Inserted %d.", reference->sequenceNumber);
} }
} }
// forward to application layer
debug(DEBUG_DATARECEIVER, "forward %u", seqno);
XlapTimeStampClock(sock_ptr, ts_data_packet, seqno, PrrtReturnPackage); XlapTimeStampClock(sock_ptr, ts_data_packet, seqno, PrrtReturnPackage);
XlapTimeStampCycle(sock_ptr, ts_data_packet, seqno, PrrtReturnPackage); XlapTimeStampCycle(sock_ptr, ts_data_packet, seqno, PrrtReturnPackage);
} }
...@@ -181,6 +195,10 @@ static void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { ...@@ -181,6 +195,10 @@ static void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
} }
static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) { static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) {
PrrtPacketRedundancyPayload *payload = packet->payload;
prrtTimestamp_t sentTimestamp = payload->timestamp;
socket->lastSentTimestamp = sentTimestamp;
PrrtPacketRedundancyPayload *redundancyPayload = packet->payload; PrrtPacketRedundancyPayload *redundancyPayload = packet->payload;
PrrtReceptionTable_mark_received(socket->redundancyReceptionTable, packet->sequenceNumber); PrrtReceptionTable_mark_received(socket->redundancyReceptionTable, packet->sequenceNumber);
...@@ -201,9 +219,9 @@ static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) { ...@@ -201,9 +219,9 @@ static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) {
redundancyPayload->baseSequenceNumber); redundancyPayload->baseSequenceNumber);
PrrtRepairBlockStore_insert(socket->repairBlockStore, block); PrrtRepairBlockStore_insert(socket->repairBlockStore, block);
}
retrieve_data_blocks(socket, redundancyPayload->baseSequenceNumber, block->codingParams->k, block); retrieve_data_packets_for_block(socket, redundancyPayload->baseSequenceNumber, block->codingParams->k, block);
}
if (PrrtBlock_insert_redundancy_packet(block, packet)) { if (PrrtBlock_insert_redundancy_packet(block, packet)) {
decode_block(socket, block); decode_block(socket, block);
...@@ -213,31 +231,15 @@ static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) { ...@@ -213,31 +231,15 @@ static void handle_redundancy_packet(PrrtSocket *socket, PrrtPacket *packet) {
} }
} }
void handle_feedback_packet(PrrtSocket *prrtSocket, PrrtPacket *prrtPacket, prrtTimestamp_t receiveTime) { void handle_feedback_packet(PrrtSocket *socket, PrrtPacket *packet, prrtTimestamp_t receiveTime) {
check(prrtPacket != NULL, "Cannot be null"); check(packet != NULL, "Cannot be null");
debug(DEBUG_DATARECEIVER, "handle_feedback_packet"); debug(DEBUG_DATARECEIVER, "handle_feedback_packet");
PrrtPacketFeedbackPayload *feedbackPayload = (PrrtPacketFeedbackPayload *) prrtPacket->payload; PrrtPacketFeedbackPayload *feedbackPayload = (PrrtPacketFeedbackPayload *) packet->payload;
prrtTimestamp_t forwardTripTimestamp = feedbackPayload->forwardTripTimestamp_us; prrtTimestamp_t forwardTripTimestamp = feedbackPayload->forwardTripTimestamp_us;
bool valid_sample = PrrtReceiver_updateAndGenerateRateSample(prrtSocket->receiver, prrtTimedelta_t rtt = (prrtTimedelta_t) (receiveTime - forwardTripTimestamp);
feedbackPayload->ackSequenceNumber,
feedbackPayload->ackPacketType, receiveTime);
debug(DEBUG_DATARECEIVER, "PrrtReceiver_updateAndGenerateRateSample ");
if (valid_sample) { PrrtReceiver_on_ack(socket->receiver, feedbackPayload, receiveTime, rtt, socket->applicationConstraints);
PrrtChannelStateInformation_update_delivery_rate(prrtSocket->receiver->csi,
prrtSocket->receiver->rateSample->delivery_rate);
}
PrrtChannelStateInformation_update_app_limited(prrtSocket->receiver->csi,
prrtSocket->receiver->rateSample->is_app_limited);
debug(DEBUG_DATARECEIVER, "PrrtChannelStateInformation_update_app_limited ");
PrrtChannelStateInformation_update_rtprop(prrtSocket->receiver->csi,
(prrtTimedelta_t) (receiveTime - forwardTripTimestamp));
debug(DEBUG_DATARECEIVER, "PrrtChannelStateInformation_update_rtprop ");
PrrtChannelStateInformation_update_plr(prrtSocket->receiver->csi, feedbackPayload->erasureCount,
feedbackPayload->packetCount);
debug(DEBUG_DATARECEIVER, "PrrtChannelStateInformation_update_plr ");
return; return;
error: error:
...@@ -297,6 +299,7 @@ void *receive_data_loop(void *ptr) { ...@@ -297,6 +299,7 @@ void *receive_data_loop(void *ptr) {
PrrtSocket *s = ptr; PrrtSocket *s = ptr;
while (1) { while (1) {
debug(DEBUG_DATARECEIVER, "About to receive.");
XlapTimestampPlaceholder tsph1; XlapTimestampPlaceholder tsph1;
XlapTimestampPlaceholder tsph2; XlapTimestampPlaceholder tsph2;
XlapTimestampPlaceholder tsph3; XlapTimestampPlaceholder tsph3;
...@@ -307,9 +310,7 @@ void *receive_data_loop(void *ptr) { ...@@ -307,9 +310,7 @@ void *receive_data_loop(void *ptr) {
struct timespec packet_recv_timestamp; struct timespec packet_recv_timestamp;
uint64_t packet_recv_cyclestamp = 0; uint64_t packet_recv_cyclestamp = 0;
receive_from_socket(s, buffer, &n, &remote, &addrlen, &packet_recv_timestamp, &packet_recv_cyclestamp); receive_from_socket(s, buffer, &n, &remote, &addrlen, &packet_recv_timestamp, &packet_recv_cyclestamp);
if (PrrtSocket_closing(s)) { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
break;
}
debug(DEBUG_HARDSTAMPING, "Packet TS:\t%ld.%09ld; Who? %s", (long) packet_recv_timestamp.tv_sec, debug(DEBUG_HARDSTAMPING, "Packet TS:\t%ld.%09ld; Who? %s", (long) packet_recv_timestamp.tv_sec,
packet_recv_timestamp.tv_nsec, inet_ntoa(remote.sin_addr)); packet_recv_timestamp.tv_nsec, inet_ntoa(remote.sin_addr));
...@@ -327,6 +328,7 @@ void *receive_data_loop(void *ptr) { ...@@ -327,6 +328,7 @@ void *receive_data_loop(void *ptr) {
prrtPacketType_t packetType = PrrtPacket_type(packet); prrtPacketType_t packetType = PrrtPacket_type(packet);
debug(DEBUG_DATARECEIVER, "received packet %d:%u", (int) packetType, seqno); debug(DEBUG_DATARECEIVER, "received packet %d:%u", (int) packetType, seqno);
packet->channelReceive = packet_recv_timestamp;
enum XlapTimestampPacketKind kind = ts_any_packet; enum XlapTimestampPacketKind kind = ts_any_packet;
prrtTimestamp_t sentTimestamp; prrtTimestamp_t sentTimestamp;
...@@ -369,9 +371,8 @@ void *receive_data_loop(void *ptr) { ...@@ -369,9 +371,8 @@ void *receive_data_loop(void *ptr) {
debug(DEBUG_DATARECEIVER, "Cleanup"); debug(DEBUG_DATARECEIVER, "Cleanup");
PrrtSocket_cleanup(s); PrrtSocket_cleanup(s);
debug(DEBUG_DATARECEIVER, "Cleaned"); debug(DEBUG_DATARECEIVER, "Cleaned");
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
} }
PrrtSocket_cleanup(s);
return NULL;
error: error:
PERROR("receive_data_loop() ended unexpectedly."); PERROR("receive_data_loop() ended unexpectedly.");
......
...@@ -2,12 +2,15 @@ ...@@ -2,12 +2,15 @@
#include <netdb.h> #include <netdb.h>
#include <string.h> #include <string.h>
#include "../../defines.h" #include "../../defines.h"
#include "../timer.h"
#include "../receiver.h" #include "../receiver.h"
#include "../socket.h" #include "../socket.h"
#include "../types/block.h" #include "../types/block.h"
#include "../../util/dbg.h" #include "../../util/dbg.h"
#include "../../util/common.h" #include "../../util/common.h"
#include "../../util/time.h"
#include "dataTransmitter.h" #include "dataTransmitter.h"
#include <math.h>
bool send_to_socket(PrrtSocket* sock_ptr, uint8_t* buf, prrtPacketLength_t length, struct timespec *packet_timestamp, uint64_t* packet_clockstamp) { bool send_to_socket(PrrtSocket* sock_ptr, uint8_t* buf, prrtPacketLength_t length, struct timespec *packet_timestamp, uint64_t* packet_clockstamp) {
PrrtReceiver *recv = sock_ptr->receiver; PrrtReceiver *recv = sock_ptr->receiver;
...@@ -77,6 +80,41 @@ static bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { ...@@ -77,6 +80,41 @@ static bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
uint8_t buf[MAX_PAYLOAD_LENGTH]; uint8_t buf[MAX_PAYLOAD_LENGTH];
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
prrtPacketLength_t length = PrrtPacket_size(packet); prrtPacketLength_t length = PrrtPacket_size(packet);
prrtPacketLength_t payloadLength = packet->payloadLength;
bool paceSuccessful = PrrtSocket_pace(sock_ptr);
if (!paceSuccessful) {
debug(DEBUG_DATATRANSMITTER, "Pacing interrupted.");
PrrtPacket_destroy(packet);
return false;
}
debug(DEBUG_DATATRANSMITTER, "Pacing interval passed.");
bool waitSuccessful = PrrtReceiver_wait_for_space(sock_ptr->receiver, sock_ptr->maximum_payload_size,
sock_ptr->applicationConstraints);
if(!waitSuccessful) {
debug(DEBUG_DATATRANSMITTER, "Wait for space interrupted.");
PrrtPacket_destroy(packet);
return false;
}
debug(DEBUG_DATATRANSMITTER, "Space available.");
prrtTimestamp_t now = PrrtClock_get_current_time_us();
if (sock_ptr->pacingEnabled) {
double pacing_rate = PrrtReceiver_getBBRPacingRate(sock_ptr->receiver);
if(pacing_rate != 0) {
prrtTimedelta_t pacingTime = (prrtTimedelta_t) round(((1000 * 1000 * ( (double)payloadLength)) / pacing_rate));
debug(DEBUG_DATATRANSMITTER, "Payload: %u, PacingRate: %f, Pacing Time: %u", packet->payloadLength, pacing_rate, pacingTime);
sock_ptr->nextSendTime = now + pacingTime;
}
}
// Update timestamp
if(PrrtPacket_type(packet) == PACKET_TYPE_DATA) {
((PrrtPacketDataPayload*) (packet->payload))->timestamp = PrrtClock_get_current_time_us();
((PrrtPacketDataPayload*) (packet->payload))->btlbw = PrrtReceiver_get_BBR_btlDr(sock_ptr->receiver);
} else if(PrrtPacket_type(packet) == PACKET_TYPE_REDUNDANCY) {
((PrrtPacketRedundancyPayload*) (packet->payload))->timestamp = PrrtClock_get_current_time_us();
}
check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, packet), "Buffer too small."); check(PrrtPacket_encode(buf, MAX_PAYLOAD_LENGTH, packet), "Buffer too small.");
...@@ -125,57 +163,110 @@ static bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) { ...@@ -125,57 +163,110 @@ static bool send_packet(PrrtSocket *sock_ptr, PrrtPacket *packet) {
return false; return false;
} }
void *send_data_loop(void *ptr) { typedef struct timer_arg {
PrrtSocket *sock_ptr = ptr; PrrtSocket* socket;
PrrtBlock *block = NULL; PrrtBlock* block;
} RetransmissionTimerArgs;
while (1) { void retransmission_round_handler(void *arg) {
ListNode *job; uint8_t j;
do { RetransmissionTimerArgs* args = (RetransmissionTimerArgs*) arg;
job = Pipe_pull(sock_ptr->sendDataQueue);
if (PrrtSocket_closing(sock_ptr)) { PrrtBlock *block = args->block;
if (block != NULL) { PrrtSocket *socket = args->socket;
PrrtBlock_destroy(block);
} if(block->inRound > 0) {
return NULL; PrrtReceiver_rto_check(socket->receiver, socket->applicationConstraints);
} }
} while (!job);
PrrtPacket *packet = PrrtPacket_byListNode(job); if (PrrtSocket_closing(socket) || block->inRound >= block->codingParams->c) {
XlapTimeStampClock(sock_ptr, ts_data_packet, packet->sequenceNumber, PrrtTransmitStart); PrrtBlock_destroy(block);
XlapTimeStampCycle(sock_ptr, ts_data_packet, packet->sequenceNumber, PrrtTransmitStart); free