diff --git a/src/Makefile b/src/Makefile index caa2545..411c969 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,7 +5,7 @@ clean: rm testSend redcore: - gcc redcore.c redpacket.c route.c redhost.c redinterface.c redprotocol.c redctl.c -o redcore -Wconversion -Wsign-compare + gcc redcore.c redpacket.c route.c redhost.c redinterface.c redprotocol.c redctl.c redprocessor.c -o redcore -Wconversion -Wsign-compare testSend: gcc testSend.c redpacket.c -o testSend diff --git a/src/redcore.c b/src/redcore.c index 5dbaaf6..f2d451f 100644 --- a/src/redcore.c +++ b/src/redcore.c @@ -70,6 +70,7 @@ #include #include "redprotocol.h" #include "redctl.h" +#include "redprocessor.h" /** * Prototypes (TODO: Own header file) @@ -81,8 +82,6 @@ int eProcessorLoop(); int iPacketLoop(); int ePacketLoop(); void startup(char**, long); -void process(struct redPacket); -void ingest(struct redPacket); char startSubsystems(); void tidyUp(); @@ -119,7 +118,7 @@ void config(char* filename) /* List of interface names to run on*/ char** interfaceNames; -char isBroadcastAddress(unsigned long); + int main(int argc, char** args) { @@ -306,103 +305,7 @@ int eProcessorLoop() } -/** -* Returns true if the given address -* is an address assigned to this redNode -* -* @param true if address is local, false -* otherwise -*/ -char isLocalAddress(long address) -{ - return 1; /* TODO: Implement me */ -} -/** -* Returns true if the given address -* is a broadcast address -* -* @param true if address is broadcast, -* false otherwise -*/ -char isBroadcastAddress(unsigned long address) -{ - /* The broadcast address is all 1-bits/highest-value unsigned long */ - return address == -1; -} - -/** -* Accepts a packet into the system -* and passes it up to the correct -* protocol handler -*/ -void ingest(struct redPacket rp) -{ - /* TODO: Implement the redControl handler */ - - printf("Ingestion happenine\n"); - - /** - * If the protocol type is 0, then - * handle the redControl packet - */ - if(!rp.type) - { - /* TODO: Implement */ - } - /* Search for a protocol handler */ - else - { - /* TODO: Implement protocol handlers array search */ - } -} - - -void process(struct redPacket rp) -{ - /* Only continue if the version is 0 */ - if(!rp.version) - { - /* TODO: Destination address handling */ - /** - * If the address is a broadcast address - * or one of ours - */ - if(isBroadcastAddress(rp.destination) || isLocalAddress(rp.destination)) - { - /* Accept the redPacket into the protocol dispatcher */ - printf("Packet destined to us\n"); - ingest(rp); - } - /* TODO: Multicast handling */ - /* If the packet wasn't destined to us */ - else - { - /* TODO: Check if forwarding is enabled */ - if(isForwarding) - { - /* TODO: Implement forwarding */ - - /* TODO: Implement ttl check before anything else */ - } - else - { - /* Drop it */ - printf("Received packet with address not destined to us, dropping (forwarding disabled)\n"); - } - } - - - /* TODO: Possible source address handling */ - - /* TODO: Dependant on destination address, check TTL */ - } - /* If not, then drop the redPacket */ - else - { - printf("Dropping redPacket with non-zero version field: %u\n", rp.version); - } -} void initializeProtocolHandlers(struct redProtocol* protocols, long count) { diff --git a/src/redprocessor.c b/src/redprocessor.c new file mode 100644 index 0000000..b02e228 --- /dev/null +++ b/src/redprocessor.c @@ -0,0 +1,101 @@ +extern char isForwarding; + +#include "redpacket.h" + +/** +* Returns true if the given address +* is an address assigned to this redNode +* +* @param true if address is local, false +* otherwise +*/ +char isLocalAddress(long address) +{ + return 1; /* TODO: Implement me */ +} + +/** +* Returns true if the given address +* is a broadcast address +* +* @param true if address is broadcast, +* false otherwise +*/ +char isBroadcastAddress(unsigned long address) +{ + /* The broadcast address is all 1-bits/highest-value unsigned long */ + return address == -1; +} + +/** +* Accepts a packet into the system +* and passes it up to the correct +* protocol handler +*/ +void ingest(struct redPacket rp) +{ + /* TODO: Implement the redControl handler */ + + printf("Ingestion happenine\n"); + + /** + * If the protocol type is 0, then + * handle the redControl packet + */ + if(!rp.type) + { + /* TODO: Implement */ + } + /* Search for a protocol handler */ + else + { + /* TODO: Implement protocol handlers array search */ + } +} + + +void process(struct redPacket rp) +{ + /* Only continue if the version is 0 */ + if(!rp.version) + { + /* TODO: Destination address handling */ + /** + * If the address is a broadcast address + * or one of ours + */ + if(isBroadcastAddress(rp.destination) || isLocalAddress(rp.destination)) + { + /* Accept the redPacket into the protocol dispatcher */ + printf("Packet destined to us\n"); + ingest(rp); + } + /* TODO: Multicast handling */ + /* If the packet wasn't destined to us */ + else + { + /* TODO: Check if forwarding is enabled */ + if(isForwarding) + { + /* TODO: Implement forwarding */ + + /* TODO: Implement ttl check before anything else */ + } + else + { + /* Drop it */ + printf("Received packet with address not destined to us, dropping (forwarding disabled)\n"); + } + } + + + /* TODO: Possible source address handling */ + + /* TODO: Dependant on destination address, check TTL */ + } + /* If not, then drop the redPacket */ + else + { + printf("Dropping redPacket with non-zero version field: %u\n", rp.version); + } +} \ No newline at end of file diff --git a/src/redprocessor.h b/src/redprocessor.h new file mode 100644 index 0000000..6c91150 --- /dev/null +++ b/src/redprocessor.h @@ -0,0 +1,4 @@ +void process(struct redPacket); +void ingest(struct redPacket); +char isBroadcastAddress(unsigned long); +char isLocalAddress(long); \ No newline at end of file