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

Nd rfc6775 implementation for tinyos blip stack #295

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion tools/tinyos/c/blip/lib6lowpan/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ enum {
ICMP_TYPE_ROUTER_ADV = 134,
ICMP_TYPE_NEIGHBOR_SOL = 135,
ICMP_TYPE_NEIGHBOR_ADV = 136,
ICMP_TYPE_DUPLICATE_REQ = 157,
ICMP_TYPE_DUPLICATE_CONFIRM = 158,
ICMP_TYPE_RPL_CONTROL = 155,
ICMP_NEIGHBOR_HOPLIMIT = 255,

ICMP_CODE_HOPLIMIT_EXCEEDED = 0,
ICMP_CODE_ASSEMBLY_EXCEEDED = 1,
};
Expand Down
43 changes: 43 additions & 0 deletions tos/interfaces/Node.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
@author Md.Jamal <[email protected]>
@version $Revision: 1.0

*/

interface Node {


/* It is used to set the node acts as Host*/

command void setHost();


/*It is used to check whether the node is host or not
Returns FALSE if it is not a host
Returns TRUE if it is a host*/

command bool getHostState();


/* It is used to unset the Node from Host */
command void unsetHost();

/* It is used to set the node to act as Router*/
command void setRouter();

/* It is used to check whether the node is router or not
Returns FALSE when it is not a Router
Returns TRUE when it is Router */
command bool getRouterState();

/* It is used to set the node to act as 6LoWPAN Border Router*/
command void setLBR();


/* It is used to check whether the node is EdgeRouter or Not
Returns FALSE when it is not a EdgeRouter
Returns TRUE when it is a EdgeRouter*/

command bool getLBRState();

}
15 changes: 15 additions & 0 deletions tos/lib/net/blip/IPAddressP.nc
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,19 @@ module IPAddressP {

event void Ieee154Address.changed() {}



command bool IPAddress.getEUILLAddress(struct in6_addr *addr)
{
int i;
ieee154_laddr_t laddr = call Ieee154Address.getExtAddr();//getting the Extended Address

memclr(addr->s6_addr, 16); //clearing the address passed
addr->s6_addr16[0] = htons(0xfe80); // setting the prefix as fe80
//copying the EUI-64 into interface identifier
for (i = 0; i < 8; i++)
addr->s6_addr[8+i] = laddr.data[7-i];
addr->s6_addr[8] ^= 0x2; /* toggle U/L bit */
return TRUE;
}
}
33 changes: 33 additions & 0 deletions tos/lib/net/blip/IPForwardingEngineP.nc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module IPForwardingEngineP {
interface IPAddress;
interface IPPacket;
interface Pool<struct in6_iid>;
interface RouterList;
interface NeighbrCache;

#ifdef PRINTFUART_ENABLED
interface Timer<TMilli> as PrintTimer;
Expand Down Expand Up @@ -193,6 +195,7 @@ module IPForwardingEngineP {
}

command error_t IP.send(struct ip6_packet *pkt) {
struct in6_addr next;
struct route_entry *next_hop_entry =
call ForwardingTable.lookupRoute(pkt->ip6_hdr.ip6_dst.s6_addr, 128);

Expand Down Expand Up @@ -240,6 +243,25 @@ module IPForwardingEngineP {
return do_send(next_hop_entry->ifindex, &next_hop_entry->next_hop, pkt);
}

//check whether any entry exists in the Neighbor Cache
if(call NeighbrCache.findEntry(pkt->ip6_hdr.ip6_dst)){
//printf("found from neighbor cache");
return call IPForward.send[ROUTE_IFACE_154](&pkt->ip6_hdr.ip6_dst, pkt, NULL);
}

#ifdef NODE_ROUTER //if u r a router and if u dont have any information about the destination send it to the LBR
call NeighbrCache.getLBRAddress(&next);
return do_send(ROUTE_IFACE_154,&next,pkt);
#endif
#ifdef NODE_HOST //if u r a host and if u dont have any information about the destination send it to the router
//RFC 6775(Section 5.6) Send to the Default Router IP and send it to the Default Router as the destination is OFF-Link
if(call RouterList.getRouterIP(&next)!=-1)
{
//printf("\n Using Router to send the packet for:");
//printf_in6addr(&pkt->ip6_hdr.ip6_dst);
return do_send(ROUTE_IFACE_154,&next,pkt); //just convert it into linklocal address here
}
#endif
printf("Forwarding -- no route found for packet. FAIL.\n");
printf("Forwarding -- dest addr: ");
printf_in6addr(&pkt->ip6_hdr.ip6_dst);
Expand Down Expand Up @@ -296,6 +318,12 @@ module IPForwardingEngineP {
/* oops, no route. */
/* RPL will reencapsulate the packet in some cases here */
// call ForwardingEvents.drop(iph, payload, len, ROUTE_DROP_NOROUTE);
if(call NeighbrCache.findEntry(iph->ip6_dst))
{
//printf("\n Got entry from destination cache");
do_send(ROUTE_IFACE_154, &iph->ip6_dst,&pkt);
return;
}
return;
}
next_hop = &next_hop_entry->next_hop;
Expand Down Expand Up @@ -383,5 +411,10 @@ module IPForwardingEngineP {
default event void ForwardingTableEvents.defaultRouteAdded() {}
default event void ForwardingTableEvents.defaultRouteRemoved() {}

event void NeighbrCache.default_rtrlistempty(){}

event void NeighbrCache.NUD_reminder(struct in6_addr ip_address){}

event void NeighbrCache.prefixReg(){}
event void IPAddress.changed(bool global_valid) {}
}
3 changes: 3 additions & 0 deletions tos/lib/net/blip/IPNeighborDiscoveryC.nc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ configuration IPNeighborDiscoveryC {
IPForward = IPNeighborDiscoveryP.IPForward;
StdControl = IPNeighborDiscoveryP.StdControl;

components NeighbrCacheC;
IPNeighborDiscoveryP.NeighbrCache -> NeighbrCacheC;

IPNeighborDiscoveryP.IP_RS -> ICMP_RS.IP[ICMPV6_CODE_RS];
IPNeighborDiscoveryP.IP_RA -> ICMP_RA.IP[ICMPV6_CODE_RA];
IPNeighborDiscoveryP.RSTimer -> RSTimer.Timer;
Expand Down
18 changes: 16 additions & 2 deletions tos/lib/net/blip/IPNeighborDiscoveryP.nc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module IPNeighborDiscoveryP {
interface IPLower;
interface IPAddress;
interface Ieee154Address;
interface NeighbrCache;

#if BLIP_ADDR_AUTOCONF
interface SetIPAddress;
Expand Down Expand Up @@ -511,13 +512,20 @@ module IPNeighborDiscoveryP {

if (call NeighborDiscovery.resolveAddress(&local_addr, &fr_addr.ieee_src) !=
SUCCESS) {
printf("IPND - local address resolution failed\n");
//this is if ip exist in the neighbor cache not in routing table
if(call NeighbrCache.resolveIP(&local_addr,&fr_addr.ieee_src)!=SUCCESS) {
// printf("IPND - local address resolution failed\n");
return FAIL;
}
return FAIL;
}

if (call NeighborDiscovery.resolveAddress(next, &fr_addr.ieee_dst) !=
SUCCESS) {
printf("IPND - next-hop address resolution failed\n");
if(call NeighbrCache.resolveIP(next,&fr_addr.ieee_dst) != SUCCESS){
// printf("IPND - next-hop address resolution failed");
return FAIL;
}
return FAIL;
}
printf("l2 source: "); printf_ieee154addr(&fr_addr.ieee_src);
Expand All @@ -540,4 +548,10 @@ module IPNeighborDiscoveryP {

event void Ieee154Address.changed() {}
event void IPAddress.changed(bool global_valid) {}

event void NeighbrCache.default_rtrlistempty(){}

event void NeighbrCache.NUD_reminder(struct in6_addr ip_address){}

event void NeighbrCache.prefixReg(){}
}
5 changes: 5 additions & 0 deletions tos/lib/net/blip/IPStackC.nc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ configuration IPStackC {
FwdP.IPPacket -> IPPacketC.IPPacket;
IPProtocolsP.IPPacket -> IPPacketC.IPPacket;
IPStackControlP.IPAddress -> IPAddressC.IPAddress;

components NeighbrCacheC;
FwdP.RouterList->NeighbrCacheC;
FwdP.NeighbrCache->NeighbrCacheC;


components new PoolC(struct in6_iid, N_CONCURRENT_SENDS) as FwdAddrPoolC;
FwdP.Pool -> FwdAddrPoolC;
Expand Down
18 changes: 18 additions & 0 deletions tos/lib/net/blip/MinuteConfigurationC.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
configuration MinuteConfigurationC {
provides interface MinuteTimer[uint8_t id];
}
implementation {
components MinuteTimerP;

#if defined(PLATFORM_TELOSB) || defined(PLATFORM_IWISE) || defined(PLATFORM_SMOTE)
components new AlarmMilli32C() as Alarm, new AlarmToTimerC(TMilli) as AlarmToTimer;
#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS)
components AlarmCounterMilliP as Alarm, new AlarmToTimerC(TMilli) as AlarmToTimer;
#endif
components new VirtualizeTimerC(TMilli,uniqueCount("Minute"));
MinuteTimer=MinuteTimerP;
MinuteTimerP.Timer->VirtualizeTimerC;
VirtualizeTimerC.TimerFrom -> AlarmToTimer;
AlarmToTimer.Alarm -> Alarm;

}
14 changes: 14 additions & 0 deletions tos/lib/net/blip/MinuteTimerC.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

#include "Timer.h"
generic configuration MinuteTimerC()
{
provides interface MinuteTimer[uint8_t id];

}

implementation
{

components MinuteConfigurationC;
MinuteTimer=MinuteConfigurationC;
}
69 changes: 69 additions & 0 deletions tos/lib/net/blip/MinuteTimerP.nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

module MinuteTimerP
{
provides interface MinuteTimer[uint8_t id];
uses interface Timer<TMilli> as Timer[uint8_t num];
uses interface Leds;
}

implementation
{

enum
{
RUNNING=1,
STARTING=2,
FIRED=3,
COMPLETED=4,


};

uint8_t STATE[uniqueCount("Minute")];
uint16_t period[uniqueCount("Minute")];
uint16_t count[uniqueCount("Minute")];


event void Timer.fired[uint8_t num]()
{

count[num]++;
if(STATE[num]==FIRED)
{
if(count[num]==2*period[num])
{
STATE[num]=COMPLETED;

}
else
{
call Timer.startOneShot[num](30720U); //30seconds=30*1024
}
}

if(STATE[num]==COMPLETED)
{

signal MinuteTimer.fired[num]();
call Timer.stop[num]();
count[num]=0;

}


}

command error_t MinuteTimer.startOneShot[uint8_t id](uint16_t minutes)
{
period[id]=minutes;
call Timer.startOneShot[id](30720U); //30seconds=30*1024
STATE[id]=FIRED;
return SUCCESS;

}

default event void MinuteTimer.fired[uint8_t id](){
}


}
Loading