Skip to content

Commit

Permalink
WIP: refactoring and more checks in prince source (#32)
Browse files Browse the repository at this point in the history
* add cmake build definition, remove makefile

* create include directories for headers

* add install target to cmake

* switch to custom types for topology, node and prince_handler

* use a common free_<type> approach in all our data structures

* move topology struct and functions to topology module

* format nicely parser.c

* format nicely control flow, add nicer errors and log messages

* refactor prince_handler constructor

* print errors for new socker

* format nicely socket, parser, config modules

* fix return code for main, print error when opening shared library

* refactor config module

- use types
- more error messages
- avoid exiting on unknown configuration keys

* define names for invalid structs and use them

* format nicely functions in plugin interface header

* explicitly state that netjson has been chosen as default

* order headers in oonf library

* refactor topology module

- more error checking on malloc
- format nicely

* indent correctly

* rename module parser to topology_parser

* move plugin type declaration to common header

* add missing get_initial_timers implementation to oonf library

* create load_plugin module

* create prince_handler module

- move structs and constructor/destructor to module
- set up cmake for new module

* create config structs for graph and proto, make new modules

this is very tricky as it requires freeing two more pointers in
prince_handler_t and adding functions to create and free this new
structs

* add graph_config and proto_config when creating a prince_handler

* early return when supplied conf poiter is invalid

* implement loading of plugin functions

* check malloc in new plugin implementation for olsr

* do sanity check in prince main function

* fix get_topology to behave as unix suppose

* free temporary prince_handler in config modules

* fix graph_parser header, format nicely source

* more checks in prince main on bad pointers

* follow unix conventions

- return 0 on success
- be portable

* refactor for error checking

- check for mallocs
- check for return values

* parse netjson and add error messages for unknown keys

* update error check in prince

* move test directory outside of prince

* more error checking in olsr and socket

* remove graph_parser reference

as there is a custom parser for topology data
we don't need to supply it to a plugin

* fix indentation issue

* remove http_receive function as it's not used

* fix new_plugin_p signature

* update readme

* move creation of graph_parser in prince module

this will ensure that the graph parser is always created and freed
from prince constructor and destructor

* add malloc check to brandes module

* move plugin creationg to prince_handler

* remove duplicate file write

* update prince_handler id from procedure

* implement valid_topo

* update error message for jsoninfo parser

* update find_node to return 0 on success

* add exponential backoff on socket connecting

* handle errors when connecting

this will provide a way to filter on the errors types when
trying to reconnect

remove loading prototype of configurations

* make get_initial_timer behave

* set default timers when none are recovered

* set protocol as olsrv1 in jsoninfo parser

* remove duplicate target

* remove duplicate declaration in brandes
  • Loading branch information
edoput authored and gabri94 committed Apr 11, 2018
1 parent c03d95b commit dfdda64
Show file tree
Hide file tree
Showing 80 changed files with 1,830 additions and 1,277 deletions.
82 changes: 82 additions & 0 deletions CMakeLists.txt
@@ -0,0 +1,82 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)

set(CMAKE_C_COMPILER gcc)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -Wall -Werror=implicit-function-declaration -O2")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -Wall -Werror=implicit-function-declaration -O2 -g")

SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/prince")

project(poprouting LANGUAGES C)

find_package(Threads)

add_executable(prince
graph-parser_c/src/biconnected.c
graph-parser_c/src/brandes.c
graph-parser_c/src/graph/graph.c
graph-parser_c/src/graph/list.c
graph-parser_c/src/graph_parser.c
graph-parser_c/src/network_change.c
prince/src/config.c
prince/src/config_proto.c
prince/src/config_graph.c
prince/src/load_plugin.c
prince/src/prince.c
prince/src/prince_handler.c
prince/src/socket.c
prince/src/topology.c
prince/src/topology_parser.c
)

target_link_libraries(prince
${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT}
m
json-c
)

include_directories(
prince/include
graph-parser_c/include
)

add_library(prince_oonf MODULE
prince/lib/oonf/oonf.c
prince/src/topology_parser.c
prince/src/socket.c
prince/src/topology.c
prince/src/topology_parser.c
)

add_library(prince_olsr MODULE
prince/lib/olsrd/olsr.c
prince/src/socket.c
prince/src/topology.c
prince/src/topology_parser.c
)

add_library(prince_test MODULE
prince/lib/testlib/test.c
prince/src/topology_parser.c
prince/src/socket.c
prince/src/topology.c
prince/src/topology_parser.c
)

install(TARGETS
prince
prince_oonf
prince_olsr
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib/prince
)

install(TARGETS
prince
prince_test
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib/prince
COMPONENT test
EXCLUDE_FROM_ALL
)
40 changes: 0 additions & 40 deletions Makefile

This file was deleted.

107 changes: 69 additions & 38 deletions README.md
@@ -1,36 +1,52 @@
# What is Prince:
Prince is an open source implementation of the PopRouting Algorithm. It has been developed as a Google Summer of Code [Project](https://summerofcode.withgoogle.com/projects/#5453035123769344) in collaboration with the University of Trento.
PopRouting is an algorithm to calculate the optimal values for the messages timers of a link state routing protocol (OLSR, OSPF, etc).
It fetch the topology data from the routing protocol, calculate the betweenness centrality for every node of the network and then push back the new timer's value. Currently it only supports OONF.

Prince is an open source implementation of the PopRouting Algorithm.
It has been developed as a Google Summer of Code
[Project](https://summerofcode.withgoogle.com/projects/#5453035123769344)
in collaboration with the University of Trento. PopRouting is an algorithm
to calculate the optimal values for the messages timers of a link state
routing protocol (OLSR, OSPF, etc). It fetches the topology data from the
routing protocol, calculate the betweenness centrality for every node of
the network and then push back the new timer's value. Currently it only supports OONF.

# How to install it:
## Linux
Install the dependencies:
`apt-get install libjson-c-dev`
## Using Prince on Openwrt / LEDE

Clone the repository in your pc with :
`git clone https://github.com/AdvancedNetworkingSystems/poprouting/`
Since v0.2 prince is in the LEDE/OpenWRT routing feeds.

Enter in the directory :
`cd poprouting`
```bash
opkg update
opkg install prince
```

Compile and install:
`make && make install`
## Using Prince with OONF

Prince requires these plugins to work: `remotecontrol, telnet, netjsoninfo`.

This is a configuration example for OONF that works with prince:

## Openwrt / LEDE
Since v0.2 prince is in the LEDE/OpenWRT routing feeds.
You just need to type:
```
opkg update
opkg install prince
```ini
[global]
plugin remotecontrol

[log]
stderr false
file /var/log/olsrd2.log

[telnet]
bindto 127.0.0.1
allowed session 10

[remotecontrol]
acl default_accept

[interface=wlan0]
[interface=lo]
```
# How to use it

## Prince Configuration
Prince can be configured with a configuration file, this is an example:
```

```json
{
"proto":{
"protocol": "oonf",
Expand All @@ -50,33 +66,48 @@ Prince can be configured with a configuration file, this is an example:
"multithreaded": 1
}
}
```

`log_file` is used to benchmark PRINCE and to check if the
timers and the centrality are correct, do not use it in production.

`json_type` is used to specify which format of json topology
we are parsing. It is used only by OLSRv1 plugin, supported values are: `netjson` or `jsoninfo`.

## Development

Install the dependencies:

```bash
apt-get install libjson-c-dev
```
Make a build directory in the repo

`log_file` is used just used to benchmark PRINCE and to check if the timers and the centrality are correct, thus it should not be used in production environment.
```bash
mkdir build && cd build
cmake ..
make
sudo make install
```

`json_type` is used to specify which format of json topology we are parsing. It is used only by OLSRv1 plugin, and the values can be: `netjson` or `jsoninfo`.
### Debug

## OONF
To use Prince with OONF you need the following plugins: `remotecontrol, telnet, netjsoninfo`.
Set the build type to debug, this will add gdb's debug symbols to the binary

This is a configuration example that works with prince:
```bash
cmake .. -DCMAKE_BUILD_TYPE=Debug
```
[global]
plugin remotecontrol

### Release

[log]
stderr false
file /var/log/olsrd2.log
Set the build type to release to ask the compiler for more error checking

[telnet]
bindto 127.0.0.1
allowed session 10
```bash
cmake .. -DCMAKE_BUILD_TYPE=Release
```

[remotecontrol]
acl default_accept
You can include gdb's debug symbols in a release using

[interface=wlan0]
[interface=lo]
```bash
cmake .. -DCMAKE_BUILD_TYPE=ReleaseWithDebug
```
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions graph-parser_c/include/graph/graph.h
@@ -0,0 +1,68 @@
/*
* File: graph.h
* Author: mb03
*
* Created on December 7, 2016, 3:48 PM
*/

#ifndef GRAPH_H
#define GRAPH_H

#include "list.h"
#include <stdbool.h>
#include <string.h>

#define INVALID_NODE_GRAPH NULL
#define INVALID_EDGE_GRAPH NULL
#define INVALID_GRAPH NULL
#define NODE_GRAPH_SIZE sizeof(struct node_graph)
#define EDGE_GRAPH_SIZE sizeof(struct edge_graph)
#define GRAPH_SIZE sizeof(struct graph)

/**
* Structs and functions used to represent a graph. Further detail in grap.c
*/
struct node_graph {
struct list neighbours;
char * name;
int node_graph_id;
};

typedef struct node_graph * node_graph_t;


struct edge_graph {
struct node_graph *to;
double value;
};

typedef struct edge_graph * edge_graph_t;


struct graph {
struct list nodes;
bool directed;
};

typedef struct graph * graph_t;


void init_graph(graph_t g);

void add_edge_graph(graph_t g,
const char * name_from,
const char * name_to,
double value,
bool directed);

void add_edge_graph_return_node_indexes(graph_t g,
const char * name_from,
const char * name_to,
double value,
bool directed,
int * nodefrom,
int * nodeto);

void free_graph(graph_t g);

#endif /* GRAPH_H */
File renamed without changes.
@@ -1,6 +1,8 @@
#ifndef GRAPH_PARSER_H_
#define GRAPH_PARSER_H_
/* Graph_Parser_lib.h */

#include "../../prince/src/parser.h"
#include "topology_parser.h"
#include "brandes.h"

/**
Expand All @@ -25,25 +27,17 @@ extern bool multithread;
extern bool stop_computing_if_unchanged;
typedef void c_graph_parser;

struct graph_parser
{
struct graph_parser {
struct graph g;


bool heuristic_b;
double * bc;
};


c_graph_parser * new_graph_parser(int weight,
int heuristic);

void graph_parser_parse_simplegraph(c_graph_parser * v,
struct topology *topo);
c_graph_parser *new_graph_parser(int weight, int heuristic);
void free_graph_parser(c_graph_parser * v);

void graph_parser_parse_simplegraph(c_graph_parser * v, topology_t topo);
void graph_parser_calculate_bc(c_graph_parser * v);

int graph_parser_compose_degree_bc_map(c_graph_parser * v,
map_id_degree_bc * map);

void delete_graph_parser(c_graph_parser * v);
int graph_parser_compose_degree_bc_map(c_graph_parser * v, map_id_degree_bc *map);
#endif /* GRAPH_PARSER_H_ */
File renamed without changes.

0 comments on commit dfdda64

Please sign in to comment.