Skip to content

Commit

Permalink
PWOSPF Project
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Ghali committed Apr 9, 2013
1 parent f666ee5 commit 5054d90
Show file tree
Hide file tree
Showing 37 changed files with 6,119 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*~
*.o
sr
*.d
79 changes: 79 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#------------------------------------------------------------------------------
# File: Makefile
#
# Note: This Makefile requires GNU make.
#
# (c) 2001,2000 Stanford University
#
#------------------------------------------------------------------------------

all : sr

CC = g++

OSTYPE = $(shell uname)

ifeq ($(OSTYPE),Linux)
ARCH = -D_LINUX_
SOCK = -lnsl
endif

ifeq ($(OSTYPE),SunOS)
ARCH = -D_SOLARIS_
SOCK = -lnsl -lsocket
endif

ifeq ($(OSTYPE),Darwin)
ARCH = -D_DARWIN_
SOCK =
endif

ifdef NO_DEBUG
CFLAGS = -g -Wall -ansi $(ARCH)
else
CFLAGS = -g -Wall -ansi -D_DEBUG_ $(ARCH)
endif

LIBS= $(SOCK) -lm -lresolv -lpthread
PFLAGS= -follow-child-processes=yes -cache-dir=/tmp/${USER}
PURIFY= purify ${PFLAGS}

sr_SRCS = sr_router.c sr_main.c \
sr_if.c sr_rt.c sr_vns_comm.c \
sr_dumper.c sr_pwospf.c sha1.c cache.c queue.c \
pwospf_neighbors.c pwospf_topology.c dijkstra_stack.c

sr_OBJS = $(patsubst %.c,%.o,$(sr_SRCS))
sr_DEPS = $(patsubst %.c,.%.d,$(sr_SRCS))

$(sr_OBJS) : %.o : %.c
$(CC) -c $(CFLAGS) $< -o $@

$(sr_DEPS) : .%.d : %.c
$(CC) -MM $(CFLAGS) $< > $@

include $(sr_DEPS)

sr : $(sr_OBJS)
$(CC) $(CFLAGS) -o sr $(sr_OBJS) $(LIBS)

sr.purify : $(sr_OBJS)
$(PURIFY) $(CC) $(CFLAGS) -o sr.purify $(sr_OBJS) $(LIBS)

.PHONY : clean clean-deps dist

clean:
rm -f *.o *~ core sr *.dump *.tar tags

clean-deps:
rm -f .*.d

dist-clean: clean clean-deps
rm -f .*.swp pwospf_stub.tar.gz

dist: dist-clean
(cd ..; tar -X pwospf_stub/exclude -cvf pwospf_stub.tar pwospf_stub/; gzip pwospf_stub.tar); \
mv ../pwospf_stub.tar.gz .

tags:
ctags *.c
Binary file added PWOSPF Specs.pdf
Binary file not shown.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
PWOSPF (Pee-Wee OSPF)
=====================

This project involves building advanced functionality on top of the <a href="https://github.com/cesarghali/SimpleRouter" target="_new">SimpleRouter</a> project. The goal is to develop a simple dynamic routing protocol, PWOSPF, so that your router can generate its forwarding table automatically based on routes advertised by other routers on the network. By the end of this project, your router is expected to be able to build its forwarding table from link-state advertisements sent from other routers, and route traffic through complex topologies containing multiple nodes.

PWOSPF
======
------
The routing protocol you will be implementing is a link state protocol that is loosely based on OSPFv2. You may find a full specification of PWOSPF <a href="" target="_new">here</a>. Note that while PWOSPF is based on OSPFv2 it is sufficiently different that referring to the OSPFv2 as a reference will not be of much help and contrarily may confuse or mislead you.

Network Topology
----------------
![Network Topology]()

The task is to implement PWOSPF within your existing router so that your router will be able to do the following:

* build the correct forwarding tables on the assignment topology.
* detect when routers join/or leave the topology and correct the forwarding tables correctly.
* inter-operate with a third party reference solution that implements pwosp.

Running Multiple Routers
------------------------
Since this project requires multiple instances of your router to run simultaneously you will want to use the -r and the -v command line options. -r allows you to specify the routing table file you want to use (e.g. -r rtable.vhost1) and -v allows you to specify the host you want to connect to on the topology (e.g. -v vhost3). Connecting to vhost3 on topology 300 should look something like:

> ./sr -t 300 -v vhost3 -r rtable.vhost3
For more information check Stanford <a href="http://yuba.stanford.edu/vns/assignments/pwospf/" target="_new">Virtual Network System</a>.

Partners
--------
Wassim Itani
Ahmad El Hajj

This project implements a simple version of the OSPF routing protocol.
References
----------
Ayman Kayssi, American University of Beirut, <a href="http://staff.aub.edu.lb/~ayman/" target="_new">More</a>.
106 changes: 106 additions & 0 deletions cache.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <stdio.h>
#include <time.h>

#include "cache.h"


void cache_push(struct cache_item* pFirstItem, struct cache_item* pNewItem)
{
if (pFirstItem->next_item != NULL)
{
pNewItem->next_item = pFirstItem->next_item;
pFirstItem->next_item = pNewItem;
}

pFirstItem->next_item = pNewItem;
}

struct cache_item* cache_pop(struct cache_item* pFirstItem)
{
if (pFirstItem->next_item == NULL)
{
return NULL;
}
else
{
struct cache_item* pResult = pFirstItem->next_item;

pFirstItem->next_item = pFirstItem->next_item->next_item;

return pResult;
}
}

struct cache_item* cache_search(struct cache_item* pFirstItem, uint32_t IP)
{
struct cache_item* ptr = pFirstItem->next_item;

while(ptr != NULL)
{
if (ptr->ip == IP)
{
return ptr;
}
ptr = ptr->next_item;
}

return NULL;
}

struct cache_item* cache_create_item(uint32_t ip, unsigned char mac[ETHER_ADDR_LEN], int time_stamp)
{
struct cache_item* cache_new_item = ((cache_item*)(malloc(sizeof(cache_item))));
cache_new_item->ip = ip;
for (int i = 0; i < ETHER_ADDR_LEN; i++)
{
cache_new_item->mac[i] = mac[i];
}
cache_new_item->time_stamp = time_stamp;
cache_new_item->next_item = NULL;
return cache_new_item;
}

void check_cache(struct cache_item* pFirstItem)
{
time_t time_stamp;
time(&time_stamp);
int current_time_stamp = ((int)(time_stamp));

struct cache_item* ptr = pFirstItem;

while(ptr != NULL)
{
if (ptr->next_item == NULL)
{
break;
}

if (current_time_stamp - ptr->next_item->time_stamp >= 15)
{
in_addr ip_addr;
ip_addr.s_addr = ptr->next_item->ip;
Debug("\n\n**** Removing cache entry, [%s, ", inet_ntoa(ip_addr));
DebugMAC(ptr->next_item->mac);
Debug("] *****\n\n");

remove_cache_item(ptr);

}

ptr = ptr->next_item;
}
}

void remove_cache_item(struct cache_item* previous_item)
{
if (previous_item->next_item->next_item != NULL)
{
previous_item->next_item = previous_item->next_item->next_item;
}
else
{
previous_item->next_item = NULL;
}

free(previous_item->next_item);
}
24 changes: 24 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef CACHE_H
#define CACHE_H

#include <stdlib.h>

#include "sr_if.h"
#include "sr_router.h"

#include "sr_protocol.h"

struct cache_item
{
uint32_t ip;
unsigned char mac[ETHER_ADDR_LEN];
int time_stamp;
struct cache_item* next_item;
} __attribute__ ((packed)) ;

void cache_push(struct cache_item*, struct cache_item*);
struct cache_item* cache_pop(struct cache_item*);
struct cache_item* cache_search(struct cache_item*, uint32_t);struct cache_item* cache_create_item(uint32_t ip, unsigned char mac[ETHER_ADDR_LEN], int time_stamp);
void check_cache(struct cache_item*);
void remove_cache_item(struct cache_item*);
#endif //CACHE_H
Expand Down
65 changes: 65 additions & 0 deletions dijkstra_stack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <stdio.h>
#include <time.h>

#include "dijkstra_stack.h"


void dijkstra_stack_push(struct dijkstra_item* dijkstra_first_item, struct dijkstra_item* dijkstra_new_item)
{
if (dijkstra_first_item->next != NULL)
{
dijkstra_new_item->next = dijkstra_first_item->next;
dijkstra_first_item->next = dijkstra_new_item;
}

dijkstra_first_item->next = dijkstra_new_item;
}

void dijkstra_stack_reorder(struct dijkstra_item* dijkstra_first_item)
{
struct dijkstra_item* ptr = dijkstra_first_item;
while (ptr->next != NULL)
{
if (ptr->next->next == NULL)
{
break;
}

if (ptr->next->cost > ptr->next->next->cost)
{
struct dijkstra_item* temp_1 = ptr->next->next->next;
struct dijkstra_item* temp_2 = ptr->next->next;
ptr->next->next->next = ptr->next;
ptr->next->next = temp_1;
ptr->next = temp_2;
}

ptr = ptr->next;
}
}

struct dijkstra_item* dijkstra_stack_pop(struct dijkstra_item* dijkstra_first_item)
{
if (dijkstra_first_item->next == NULL)
{
return NULL;
}
else
{
struct dijkstra_item* pResult = dijkstra_first_item->next;

dijkstra_first_item->next = dijkstra_first_item->next->next;

return pResult;
}
}

struct dijkstra_item* create_dikjstra_item(struct ospfv2_topology_entry* new_topology_entry, uint8_t cost)
{
struct dijkstra_item* dijkstra_new_item = ((dijkstra_item*)(malloc(sizeof(dijkstra_item))));
dijkstra_new_item->topology_entry = new_topology_entry;
dijkstra_new_item->cost = cost;
dijkstra_new_item->parent = NULL;
dijkstra_new_item->next = NULL;
return dijkstra_new_item;
}
23 changes: 23 additions & 0 deletions dijkstra_stack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef DIJKSTRA_STACK_H
#define DIJKSTRA_STACK_H

#include <stdlib.h>

#include "sr_if.h"
#include "sr_router.h"

#include "sr_protocol.h"

struct dijkstra_item
{
struct ospfv2_topology_entry* topology_entry;
uint8_t cost;
struct dijkstra_item* parent;
struct dijkstra_item* next;
} __attribute__ ((packed)) ;

void dijkstra_stack_push(struct dijkstra_item*, struct dijkstra_item*);
void dijkstra_stack_reorder(struct dijkstra_item*);
struct dijkstra_item* dijkstra_stack_pop(struct dijkstra_item*);
struct dijkstra_item* create_dikjstra_item(struct ospfv2_topology_entry*, uint8_t);
#endif //DIJKSTRA_STACK_H
Loading

0 comments on commit 5054d90

Please sign in to comment.