diff options
author | Sander Vrijders <sander.vrijders@ugent.be> | 2017-12-03 21:30:33 +0100 |
---|---|---|
committer | Dimitri Staessens <dimitri.staessens@ugent.be> | 2017-12-04 11:41:36 +0100 |
commit | b7fedbe399d561957f99fe7e95aa515b12252abb (patch) | |
tree | a58c91f1f7c70dea5ff0d5e0eaa33c0080f60c16 /src/ipcpd | |
parent | 38a6e6f26e55457f80611b3a74b17058876c762d (diff) | |
download | ouroboros-b7fedbe399d561957f99fe7e95aa515b12252abb.tar.gz ouroboros-b7fedbe399d561957f99fe7e95aa515b12252abb.zip |
ipcpd: Remove protocol buffers from link state
This will remove google protocol buffers from the link state routing
algorithm in the normal IPCP. It now uses packed structs, as supported
by the compilers of choice.
Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be>
Diffstat (limited to 'src/ipcpd')
-rw-r--r-- | src/ipcpd/normal/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/ipcpd/normal/pol/link_state.c | 56 | ||||
-rw-r--r-- | src/ipcpd/normal/pol/link_state.proto | 29 |
3 files changed, 24 insertions, 66 deletions
diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt index de0cd4af..087422d9 100644 --- a/src/ipcpd/normal/CMakeLists.txt +++ b/src/ipcpd/normal/CMakeLists.txt @@ -19,9 +19,6 @@ protobuf_generate_c(ENROLL_PROTO_SRCS ENROLL_PROTO_HDRS enroll.proto ${CMAKE_SOURCE_DIR}/src/lib/ipcp_config.proto) protobuf_generate_c(KAD_PROTO_SRCS KAD_PROTO_HDRS kademlia.proto) -# Add GPB sources of policies last -protobuf_generate_c(LS_PROTO_SRCS LS_PROTO_HDRS pol/link_state.proto) - math(EXPR PFT_EXPR "1 << 12") set(PFT_SIZE ${PFT_EXPR} CACHE STRING "Size of the PDU forwarding table") @@ -49,7 +46,7 @@ set(SOURCE_FILES ) add_executable(ipcpd-normal ${SOURCE_FILES} ${IPCP_SOURCES} - ${FLOW_ALLOC_SRCS} ${LS_PROTO_SRCS} ${KAD_PROTO_SRCS} ${ENROLL_PROTO_SRCS}) + ${FLOW_ALLOC_SRCS} ${KAD_PROTO_SRCS} ${ENROLL_PROTO_SRCS}) target_link_libraries(ipcpd-normal LINK_PUBLIC ouroboros-dev) include(AddCompileFlags) diff --git a/src/ipcpd/normal/pol/link_state.c b/src/ipcpd/normal/pol/link_state.c index 00c72069..5d16f5c3 100644 --- a/src/ipcpd/normal/pol/link_state.c +++ b/src/ipcpd/normal/pol/link_state.c @@ -26,6 +26,7 @@ #define OUROBOROS_PREFIX "link-state-routing" +#include <ouroboros/endian.h> #include <ouroboros/dev.h> #include <ouroboros/errno.h> #include <ouroboros/fqueue.h> @@ -48,19 +49,20 @@ #include <string.h> #include <pthread.h> -#include "link_state.pb-c.h" -typedef LinkStateMsg link_state_msg_t; - #define RECALC_TIME 4 #define LS_UPDATE_TIME 15 #define LS_TIMEO 60 -#define LSM_MAX_LEN 128 #define LSDB "lsdb" #ifndef CLOCK_REALTIME_COARSE #define CLOCK_REALTIME_COARSE CLOCK_REALTIME #endif +struct lsa { + uint64_t d_addr; + uint64_t s_addr; +} __attribute__((packed)); + struct routing_i { struct list_head next; @@ -462,24 +464,16 @@ static void * calculate_pff(void * o) static void send_lsm(uint64_t src, uint64_t dst) { - uint8_t buf[LSM_MAX_LEN]; - link_state_msg_t lsm = LINK_STATE_MSG__INIT; - size_t len; + struct lsa lsm; struct list_head * p; - lsm.d_addr = dst; - lsm.s_addr = src; - - len = link_state_msg__get_packed_size(&lsm); - - assert(len <= LSM_MAX_LEN); - - link_state_msg__pack(&lsm, buf); + lsm.d_addr = hton64(dst); + lsm.s_addr = hton64(src); list_for_each(p, &ls.nbs) { struct nb * nb = list_entry(p, struct nb, next); if (nb->type == NB_MGMT) - flow_write(nb->fd, buf, len); + flow_write(nb->fd, &lsm, sizeof(lsm)); } } @@ -570,12 +564,13 @@ static void forward_lsm(uint8_t * buf, static void * lsreader(void * o) { - fqueue_t * fq; - int ret; - uint8_t buf[LSM_MAX_LEN]; - size_t len; - int fd; - qosspec_t qs; + fqueue_t * fq; + int ret; + uint8_t buf[sizeof(struct lsa)]; + int fd; + qosspec_t qs; + struct lsa * msg; + size_t len; (void) o; @@ -596,20 +591,15 @@ static void * lsreader(void * o) } while ((fd = fqueue_next(fq)) >= 0) { - link_state_msg_t * msg; - len = flow_read(fd, buf, LSM_MAX_LEN); - if (len <= 0) - continue; - - msg = link_state_msg__unpack(NULL, len, buf); - if (msg == NULL) { - log_dbg("Failed to unpack link state message."); + len = flow_read(fd, buf, sizeof(*msg)); + if (len <= 0 || len != sizeof(*msg)) continue; - } - lsdb_add_link(msg->s_addr, msg->d_addr, &qs); + msg = (struct lsa *) buf; - link_state_msg__free_unpacked(msg, NULL); + lsdb_add_link(ntoh64(msg->s_addr), + ntoh64(msg->d_addr), + &qs); forward_lsm(buf, len, fd); } diff --git a/src/ipcpd/normal/pol/link_state.proto b/src/ipcpd/normal/pol/link_state.proto deleted file mode 100644 index 4e2280b0..00000000 --- a/src/ipcpd/normal/pol/link_state.proto +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - 2017 - * - * Link State message - * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., http://www.fsf.org/about/contact/. - */ - -syntax = "proto2"; - -message link_state_msg { - required uint64 d_addr = 1; - required uint64 s_addr = 2; - /* Add QoS parameters of link here */ -}; |