Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #3

Open
wants to merge 32 commits into
base: CLOSE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aaacd66
h
Mar 30, 2020
b32fef0
Implemented stop and wait
Mar 31, 2020
ae7cd45
commented out stuff
Mar 31, 2020
897c34b
Merge branch 'CLOSE' into master
NathanBlais Mar 31, 2020
9ce3944
Added tasks to make code run soother.
Apr 1, 2020
7ed019d
close
JosselineMenjivar Apr 8, 2020
a54bb66
Temp
Apr 8, 2020
08a61a9
Merge pull request #4 from NathanBlais/Temp
NathanBlais Apr 8, 2020
dd58e08
reaches close from recient side
JosselineMenjivar Apr 8, 2020
f4aadc8
Cleaned up warnings
Apr 8, 2020
775dfcd
Merge branch 'master' of github.com:NathanBlais/UCM-TinyOS-Network-Im…
Apr 8, 2020
a213495
Cleanup and sqn #
Apr 8, 2020
aca2bcf
Implemented new sender
Apr 10, 2020
8fc5eaf
finish replace original sends start add task send
Apr 10, 2020
a73776d
Tranplanted TransportP into a new file
Apr 12, 2020
bf81080
Reimplemented open
Apr 15, 2020
76bf239
g
Apr 15, 2020
0a9b1ae
reimplemented close
Apr 15, 2020
fb30f05
e
Apr 15, 2020
fdd037f
gg
Apr 15, 2020
d9d4657
sendbuff
Apr 17, 2020
9a49e3d
Timer
JosselineMenjivar Apr 17, 2020
3e406c0
d
Apr 17, 2020
238fb3a
slide
JosselineMenjivar Apr 17, 2020
1f2c0a8
Merge branch 'master' of https://github.com/NathanBlais/UCM-TinyOS-Ne…
JosselineMenjivar Apr 17, 2020
35cc9d8
Partialy implemented timmer.
Apr 17, 2020
b8280be
sending data is busted
Apr 17, 2020
af1a119
Worked on sending data and read
Apr 24, 2020
7e4a407
fixed bugs, has warnings tho
JosselineMenjivar Apr 24, 2020
b5c3e10
Got data to send
Apr 24, 2020
1ea7d20
AW works (for 1-5, gets weird higher), still need to fix noise
JosselineMenjivar May 1, 2020
a2e2d7f
Updates to window
JosselineMenjivar May 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 88 additions & 15 deletions Node.nc
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ module Node{
uses interface NeighborDiscovery;
uses interface DistanceVectorRouting;
uses interface Transport;

uses interface Queue<reciveInfo*>;
uses interface Pool<reciveInfo>;
}

implementation{
pack sendPackage;
am_addr_t nodes[10];
uint16_t SEQ_NUM=1;
char toSend[] = {'A','B','C','D','E','F','G','H','I',
'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

// Prototypes
void makePack(pack *Package, uint16_t src, uint16_t dest, uint16_t TTL, uint16_t seq, uint16_t protocol, uint8_t *payload, uint8_t length);
error_t receive(message_t* msg, pack* payload, uint8_t len);


event void Boot.booted(){
call AMControl.start();
Expand All @@ -56,58 +63,103 @@ implementation{

event void AMControl.stopDone(error_t err){}

task void receiveBufferTask(){
// If we have a values in our queue and the radio is not busy, then
// attempt to send a packet.
if(!call Queue.empty()){
reciveInfo *info;
// We are peeking since, there is a possibility that the value will not
// be successfuly sent and we would like to continue to attempt to send
// it until we are successful. There is no limit on how many attempts
// can be made.
info = call Queue.head();

// Attempt to send it.
if(SUCCESS == receive(&(info->msg),&(info->payload), info->len)){
//Release resources used if the attempt was successful
call Queue.dequeue();
call Pool.put(info);
}
}
}

event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len){
if(!call Pool.empty()){
reciveInfo *input;

input = call Pool.get();
memcpy(&(input->msg), msg, sizeof(*msg));
memcpy(&(input->payload), payload, PACKET_MAX_PAYLOAD_SIZE);
input->len = len;

// Now that we have a value from the pool we can put it into our queue.
// This is a FIFO queue.
call Queue.enqueue(input);

// Start a send task which will be delayed.
post receiveBufferTask();

return msg;
}
return msg;
}

error_t receive(message_t* msg, pack* payload, uint8_t len){
pack *contents;
error_t result; //for debug
if(len!=sizeof(pack)){
dbg(GENERAL_CHANNEL, "Unknown Packet Type %d\n", len);
return msg;
return SUCCESS;
}
contents = (pack *)payload;
contents = payload;
if (contents->TTL == 0) //Kill the packet if TTL is 0
return msg;
return SUCCESS;
contents-> TTL = (contents->TTL) - 1; //Reduce TTL

if(contents->dest == AM_BROADCAST_ADDR) {
call Flooder.send(*contents, contents->dest);
}
if (contents->dest != TOS_NODE_ID){ //Check if the packet is not meant for the current node
dbg(GENERAL_CHANNEL, "We're in Node %d \n \t\tRouting Packet- src:%d, dest %d, seq: %d, nexthop: %d, count: %d\n \n",TOS_NODE_ID, contents->src, contents->dest, contents->seq, call DistanceVectorRouting.GetNextHop(contents->dest), call DistanceVectorRouting.GetCost(contents->dest));
dbg(GENERAL_CHANNEL, "\t\tRouting Packet- src:%d, dest %d, seq: %d, nexthop: %d, count: %d\n",TOS_NODE_ID, contents->src, contents->dest, contents->seq, call DistanceVectorRouting.GetNextHop(contents->dest), call DistanceVectorRouting.GetCost(contents->dest));
if (contents->protocol == PROTOCOL_PING || contents->protocol == PROTOCOL_PINGREPLY || contents->protocol == PROTOCOL_TCP)
call Sender.send(*contents, call DistanceVectorRouting.GetNextHop(contents->dest));
result = call Sender.send(*contents, call DistanceVectorRouting.GetNextHop(contents->dest));
else
dbg(GENERAL_CHANNEL, "Recived packet with incorrect Protocol?\n");
return msg;
return SUCCESS;
} //End of the destination check. Packets should be ment for this node past this point

//Check the Protocol
if (PROTOCOL_PING == contents->protocol) {
dbg(GENERAL_CHANNEL, "Ping Message Recived:%s\n", contents->payload);
makePack(&sendPackage, TOS_NODE_ID, contents->src, MAX_TTL, contents->seq, PROTOCOL_PINGREPLY, (uint8_t *)contents->payload, PACKET_MAX_PAYLOAD_SIZE);
dbg(GENERAL_CHANNEL, "Sending Ping Reply to %d\n \n", contents->src);
call Sender.send(sendPackage, call DistanceVectorRouting.GetNextHop(contents->src));
result = call Sender.send(sendPackage, call DistanceVectorRouting.GetNextHop(contents->src));
dbg(GENERAL_CHANNEL, "RECIVE EVENT SEND result: %d \n",result);
}
else if (PROTOCOL_PINGREPLY == contents->protocol)
dbg(GENERAL_CHANNEL, "Package Payload: %s\n", contents->payload);
else if (PROTOCOL_TCP == contents->protocol)
{

call Transport.receive(contents);
call Transport.receiveBuffer(contents);
}
else
dbg(GENERAL_CHANNEL, "Recived packet with incorrect Protocol\n");

//dbg(GENERAL_CHANNEL, "Package Payload: %s\n", myMsg->payload);
return msg;
return SUCCESS;
}

event void CommandHandler.ping(uint16_t destination, uint8_t *payload){
error_t result;
dbg(GENERAL_CHANNEL, "PING EVENT \n");
dbg(GENERAL_CHANNEL, "Sucsess: %d | FAIL: %d \n",SUCCESS, FAIL);
makePack(&sendPackage, TOS_NODE_ID, destination, MAX_TTL, SEQ_NUM, PROTOCOL_PING, payload, PACKET_MAX_PAYLOAD_SIZE);
dbg(GENERAL_CHANNEL, "We're in Node: %d \n \t\tRouting Packet- src:%d, dest %d, seq: %d, nexthop: %d, count: %d\n \n", TOS_NODE_ID,TOS_NODE_ID, destination, SEQ_NUM, call DistanceVectorRouting.GetNextHop(destination), call DistanceVectorRouting.GetCost(destination));
SEQ_NUM++;
//call Sender.send(sendPackage, destination);
//call Flooder.send(sendPackage, destination);
call Sender.send(sendPackage, call DistanceVectorRouting.GetNextHop(destination));
result = call Sender.send(sendPackage, call DistanceVectorRouting.GetNextHop(destination));
dbg(GENERAL_CHANNEL, "PING EVENT result: %d \n",result);
}

event void CommandHandler.printNeighbors(){call NeighborDiscovery.print();}
Expand All @@ -120,7 +172,7 @@ implementation{

event void CommandHandler.setTestServer(uint8_t port){
socket_addr_t myAddr; //not realy needed exept to satisfy bind requirements
socket_t mySocket = call Transport.socket();
socket_t mySocket = call Transport.socket(port);

if (mySocket == 0){
dbg(TRANSPORT_CHANNEL, "Could not retrive an available socket\n");
Expand All @@ -141,21 +193,42 @@ implementation{

event void CommandHandler.setTestClient(uint8_t srcPort, uint8_t destination, uint8_t destPort, uint8_t *payload){
socket_addr_t destAddr;
uint8_t i;//, AmountWritten;
socket_t mySocket = call Transport.socket(srcPort);
destAddr.addr = destination; //filled with usless info
destAddr.port = destPort; //filled with usless info
if(call Transport.bind(srcPort, &destAddr))
if(call Transport.bind(mySocket, &destAddr))
return;
if(call Transport.connect(srcPort, &destAddr))
for(i=0; payload[i] != '\0'; i++ ){}
//call Transport.write(srcPort,payload,i);
if(call Transport.connect(mySocket, &destAddr))
return;
//save the value here into a holder to read for bugtesting
//for(i=0; payload[i] != '\0'; i++ ){}
//dbg(TRANSPORT_CHANNEL, "sizeof(payload): %d\n", i);
//dbg(TRANSPORT_CHANNEL, "payload: %s\n", payload);
//AmountWritten =
call Transport.write(srcPort,payload,i);
//call Transport.write(srcPort,toSend,26);


//add the payload to a que to be cut up and packaged to be sent after connection

//Set off timer to close or resend it after an amount of time
}

event void CommandHandler.cmdClientClose(uint8_t address, uint8_t srcPort, uint8_t destination, uint8_t destPort){
call Transport.close(srcPort);
}


event void CommandHandler.cmdServerRead(uint8_t port, uint16_t bufflen){
char buff[SOCKET_BUFFER_SIZE];
uint8_t i;
for (i = 0; i < SOCKET_BUFFER_SIZE; i++) buff[i] = '\0';


call Transport.read((socket_t)port, buff, bufflen);
dbg(GENERAL_CHANNEL, "Message Read from Application layer:%s\n", buff);
}


Expand Down
7 changes: 7 additions & 0 deletions NodeC.nc
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ implementation {

components TransportC as Transport;
Node.Transport -> Transport;

//Lists
components new PoolC(reciveInfo, 20);
components new QueueC(reciveInfo*, 20);

Node.Pool -> PoolC;
Node.Queue -> QueueC;
}
46 changes: 32 additions & 14 deletions TestSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestSim:
CMD_CLIENT_CLOSE = 7
CMD_APP_SERVER = 8
CMD_APP_CLIENT = 9
CMD_SERVER_READ = 15
CMD_ERROR = 10
CMD_APP_SEND = 11

Expand Down Expand Up @@ -156,13 +157,21 @@ def cmdClientClose(self, address, sourcePort, dest, destPort,):
self.sendCMD(self.CMD_CLIENT_CLOSE, address, "{0}{1}{2}{3}".format(chr(address), chr(sourcePort), chr(dest), chr(destPort)));
#[client adress] [srcPort] [dest] [destPort]

def cmdServerRead(self, address, port, bufflen):
print 'Server Calling Read for', address, port;
self.sendCMD(self.CMD_SERVER_READ, address, "{0}{1}".format(chr(port), chr(bufflen)));

# def cmdServerChat(self, address, port, bufflen)

def main():
s = TestSim();
s.runTime(10);
#s.loadTopo("example.topo");
s.loadTopo("long_line.topo");
#s.loadTopo("Project2Topo.topo");
s.loadNoise("no_noise.txt");
#s.loadNoise("meyer-heavy.txt");
#s.loadNoise("some_noise.txt");
s.bootAll();
#General
s.addChannel(s.COMMAND_CHANNEL);
Expand All @@ -179,30 +188,39 @@ def main():
#Project 4
s.addChannel(s.APPLICATION_CHANNEL);



#####***DVR TEST***#####

s.runTime(1);
#s.runTime(126); #Fastest time with a "151 | call advertiseTimer.startOneShot(6000);"
s.runTime(150);

for i in range(1, 19):
s.routeDMP(i);
s.runTime(1);
s.runTime(120);
s.runTime(300);
#for i in range(1, 19):
# s.routeDMP(i);
# s.runTime(1);
#s.runTime(10);
#s.ping(2, 6, "Hi!");
#s.runTime(100);
#####***TCP Test***#####
#s.ping(1, 6, "I'll have you know I gr");
s.cmdTestServer(6,10); #[adress] [port]
s.runTime(40); #no noise 100, some noise 100
# s.ping(1, 6, "I'll have you know I gr");
# s.runTime(10);
# s.ping(1, 6, "I'll have you know I gr");
# s.runTime(10);
# s.ping(1, 6, "I'll have you know I gr");
s.cmdTestClient(1,8,6,10, "Hello,_bozo!"); #[selfAdress] [srcPort] [dest] [destPort] [transfer]
s.runTime(200); #no noise 350, some noise 350
s.cmdServerRead(6,10,26); #[dest][destPort][length]
s.runTime(1); #no noise 300, some noise 300
s.cmdClientClose(1,8,6,10); #[client adress] [srcPort] [dest] [destPort]
s.runTime(100); #no noise 200, some noise 200


###***Chat Client and Server Test*** ###



#####***TCP Test***#####

s.cmdTestServer(6,1); #[adress] [port]
s.runTime(40);
s.cmdTestClient(1,1,6,1, "1234 12"); #[selfAdress] [srcPort] [dest] [destPort] [transfer]
s.runTime(120);
#s.cmdClientClose(2,80,3,10); #[client adress] [srcPort] [dest] [destPort]

#####***NEIGHBOR DISCOVERY TEST***#####
# s.runTime(50);
Expand Down
Empty file added core
Empty file.
1 change: 1 addition & 0 deletions includes/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum{
CMD_TEST_CLIENT=4,
CMD_TEST_SERVER=5,
CMD_CLIENT_CLOSE=7,
CMD_SERVER_READ=15,
CMD_KILL=6,
CMD_ERROR=9
};
Expand Down
27 changes: 19 additions & 8 deletions includes/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

enum{
PACKET_HEADER_LENGTH = 8,
TCP_HEADER_LENGTH = 10,
// PACKET_HEADER_LENGTH = sizeof(pack),
PACKET_MAX_PAYLOAD_SIZE = 28 - PACKET_HEADER_LENGTH,
TCP_PACKET_MAX_PAYLOAD_SIZE = PACKET_MAX_PAYLOAD_SIZE - 7,
TCP_PACKET_MAX_PAYLOAD_SIZE = PACKET_MAX_PAYLOAD_SIZE - TCP_HEADER_LENGTH,
//MAX_TTL = 15
MAX_TTL = 20

Expand Down Expand Up @@ -41,21 +42,31 @@ typedef struct tcpHeader{
uint8_t Seq_Num; //Sequence Number - which byte chunk is being sent
uint8_t Acknowledgment; //ACK - next byte expected (seq + 1)
uint8_t Len; //Data Offset
unsigned int Flags: 3;
//unsigned int Flags: 3;
unsigned int Flags: 6;
uint8_t Advertised_Window; // buffer size
//uint8_t Checksum; //optional
//uint8_t UrgPtr; //optional
uint8_t payload[TCP_PACKET_MAX_PAYLOAD_SIZE]; // DATA

}tcpHeader;


//Flags for TCP
#define URG 0 //signifies that this segment contains urgent data.
#define ACK 1 //is set any time the Acknowledgment field is valid, implying that the receiver should pay attention to it.
#define PUSH 2 //signifies that the sender invoked the push operation, which indicates to the receiving side of TCP that it should notify the receiving process of this fact.
#define RESET 3 //signifies that the receiver has become confused—for example, because it received a segment it did not expect to receive—and so wants to abort the connection.
#define SYN 4 //-never carries payload data
#define FIN 5 //-never carries payload data
#define URG 0x1 //signifies that this segment contains urgent data.
#define ACK 0x2 //is set any time the Acknowledgment field is valid, implying that the receiver should pay attention to it.
#define PUSH 0x4 //signifies that the sender invoked the push operation, which indicates to the receiving side of TCP that it should notify the receiving process of this fact.
#define RESET 0x8 //signifies that the receiver has become confused—for example, because it received a segment it did not expect to receive—and so wants to abort the connection.
#define SYN 0x10 //16-never carries payload data
#define FIN 0x20 //32-never carries payload data

// //Flags for TCP
// #define URG 0 //signifies that this segment contains urgent data.
// #define ACK 1 //is set any time the Acknowledgment field is valid, implying that the receiver should pay attention to it.
// #define PUSH 2 //signifies that the sender invoked the push operation, which indicates to the receiving side of TCP that it should notify the receiving process of this fact.
// #define RESET 3 //signifies that the receiver has become confused—for example, because it received a segment it did not expect to receive—and so wants to abort the connection.
// #define SYN 4 //-never carries payload data
// #define FIN 5 //-never carries payload data

/*
* logPack
Expand Down
2 changes: 1 addition & 1 deletion includes/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum{
PROTOCOL_PINGREPLY = 1,
PROTOCOL_LINKEDLIST = 2,
PROTOCOL_NAME = 3,
PROTOCOL_TCP= 4,
PROTOCOL_TCP = 4,
PROTOCOL_DV = 5,
PROTOCOL_CMD = 99
};
Expand Down
23 changes: 23 additions & 0 deletions includes/sendInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define PACK_BUFFER_H

#include "packet.h"
#include "socket.h"

enum{
SEND_BUFFER_SIZE=128
Expand All @@ -15,6 +16,28 @@ typedef struct sendInfo{
uint16_t dest;
}sendInfo;

typedef struct reciveInfo{
message_t msg;
pack payload;
uint8_t len;
}reciveInfo;

typedef struct sendTCPInfo{
socket_t socKey;
uint8_t flag;
uint8_t seq;
uint8_t ack;
pack payload;
uint8_t length;
}sendTCPInfo;

typedef struct rsendTCPInfo{
socket_t socKey;
uint8_t flag;
pack payload;
uint8_t length;
}rsendTCPInfo;

typedef struct neighbor {
uint16_t id;
bool flag;
Expand Down
Loading