鐵 玲, 任海波
(1.成都大學(xué) 信息科學(xué)與工程學(xué)院, 四川 成都 610106;2.成都世紀(jì)華寧科技有限公司, 四川 成都 610041)
基于Contiki的無線傳感器網(wǎng)絡(luò)的6LoWPAN子網(wǎng)和互聯(lián)網(wǎng)互聯(lián)研究
鐵 玲1, 任海波2
(1.成都大學(xué) 信息科學(xué)與工程學(xué)院, 四川 成都 610106;2.成都世紀(jì)華寧科技有限公司, 四川 成都 610041)
無線傳感器網(wǎng)絡(luò)是物聯(lián)網(wǎng)的重要組成部分,主要通過傳感器感受外界環(huán)境,同時(shí)將測(cè)量參數(shù)通過無線媒介傳遞給后臺(tái)服務(wù)器,并且傳感器節(jié)點(diǎn)之間可以組網(wǎng)完成數(shù)據(jù)路由功能.傳統(tǒng)的IP協(xié)議棧并不適合資源和能量受限的無線傳感器節(jié)點(diǎn),6LoWPAN技術(shù)主要完成IPv6互聯(lián)網(wǎng)與無線傳感器網(wǎng)絡(luò)之間協(xié)議和數(shù)據(jù)的轉(zhuǎn)換.通過在傳感器節(jié)點(diǎn)和嵌入式網(wǎng)關(guān)中間引入Contiki操作系統(tǒng)以及合適的IPv6協(xié)議??梢院芎玫貙?shí)現(xiàn)無線傳感器網(wǎng)絡(luò)和Internet的互聯(lián).實(shí)現(xiàn)了基于Contiki的CC2530網(wǎng)關(guān)節(jié)點(diǎn)的uIP協(xié)議棧,并設(shè)計(jì)了UDP通信協(xié)議,針對(duì)設(shè)計(jì)方案搭建合理的測(cè)試環(huán)境,并采用PING命令進(jìn)行了連通性測(cè)試實(shí)驗(yàn).
6LoWPAN;IPv6;Internet;聯(lián)接
6LoWPAN技術(shù)主要針對(duì)在無線傳感器網(wǎng)絡(luò)(wireless sensor network,WSN)上提供IPv6協(xié)議,IETF工作組的RFC4944標(biāo)準(zhǔn)[1]對(duì)IPv6分組如何在無線傳感器網(wǎng)絡(luò)上被封裝和轉(zhuǎn)發(fā)進(jìn)行了詳細(xì)說明.此外,Contiki是一種在無線傳感器網(wǎng)絡(luò)上開發(fā)的開源操作系統(tǒng)[2],在此之上實(shí)現(xiàn)了uIP(micro-IP) and lwIP TCP/IP協(xié)議棧,每個(gè)節(jié)點(diǎn)提供IPv6連接,從而實(shí)現(xiàn)無線傳感器網(wǎng)絡(luò)和IPv6互聯(lián)網(wǎng)之間全I(xiàn)P的互聯(lián)互通[3].本研究基于Contiki,實(shí)現(xiàn)一個(gè)6LoWPAN的網(wǎng)關(guān),完成IPv6協(xié)議棧和6LoWPAN協(xié)議棧的轉(zhuǎn)換,使得6LoWPAN的無線傳感器節(jié)點(diǎn)和IP網(wǎng)絡(luò)的主機(jī)能相互訪問.
基于6LoWPAN的無線傳感器網(wǎng)絡(luò)主要由IPv6的無線傳感器節(jié)點(diǎn)、6LoWPAN網(wǎng)關(guān)、IPv6網(wǎng)絡(luò)和節(jié)點(diǎn)組成,其網(wǎng)絡(luò)體系結(jié)構(gòu)如圖1所示[4].
無線傳感器節(jié)點(diǎn)支持Contiki的uIP[5]協(xié)議,其網(wǎng)絡(luò)的協(xié)議棧如圖2所示.6LoWPAN適配層是IPv6網(wǎng)絡(luò)和IEEE 802.15.4 MAC層間的一個(gè)中間層,其向
圖1 6LoWPAN網(wǎng)絡(luò)體系結(jié)構(gòu)
上提供IPv6對(duì)IEEE 802.15.4媒介訪問支持,向下則控制網(wǎng)絡(luò)構(gòu)建、拓?fù)浼癕AC層路由.6LoWPAN適配層的基本功能包括鏈路層的分片和重組、頭部壓縮、組播支持、網(wǎng)絡(luò)拓?fù)錁?gòu)建和地址分配、IPv6報(bào)文的轉(zhuǎn)發(fā).
圖2 6LoWPAN協(xié)議棧
Contiki[6]是一個(gè)適用于有內(nèi)存的嵌入式系統(tǒng)的開源、高可移植并支持網(wǎng)絡(luò)的多任務(wù)操作系統(tǒng),其系統(tǒng)架構(gòu)如圖3所示,包括一個(gè)多任務(wù)核心、TCP/IP堆棧、程序集以及低能耗的無線通信堆棧.Contiki可以在每個(gè)進(jìn)程內(nèi)選擇是否支持先占式多線程,進(jìn)程間通信通過事件利用消息來實(shí)現(xiàn).Contiki還包括一個(gè)可選的GUI子系統(tǒng),可以提供對(duì)本地終端、基于VNC的網(wǎng)絡(luò)化虛擬顯示或者Telnet的圖形化支持.
圖3 Contiki的系統(tǒng)架構(gòu)示意圖
uIP的TCP/IP協(xié)議棧是為能夠在對(duì)內(nèi)存具有嚴(yán)格要求的智能體和其他網(wǎng)絡(luò)嵌入式設(shè)備運(yùn)行而設(shè)計(jì)的.本設(shè)計(jì)中,uIP協(xié)議棧[7]主要有2個(gè)任務(wù):傳感器的數(shù)據(jù)包通過uip封裝成IP報(bào)文,然后放在緩存區(qū)里,適配層通過對(duì)其報(bào)文的頭部壓縮和分片,在通過加入相應(yīng)的mesh頭或分片來構(gòu)造6LoWPAN數(shù)據(jù)包,最后發(fā)送出去;處理由底層驅(qū)動(dòng)收到的數(shù)據(jù)包.數(shù)據(jù)的接收過程正好相反.協(xié)議實(shí)現(xiàn)的構(gòu)架圖如圖4所示.
圖4 uIP協(xié)議
本設(shè)計(jì)主要采用應(yīng)用UDP[8]來實(shí)現(xiàn)數(shù)據(jù)的轉(zhuǎn)發(fā).通過timeout-handler()函數(shù)來觸發(fā)定時(shí)器,然后調(diào)用uip-udp-packet-send()函數(shù)來實(shí)現(xiàn)發(fā)送.該函數(shù)通過調(diào)用網(wǎng)絡(luò)層驅(qū)動(dòng)sicslowpan.c文件中的sicslowpan-init(void)來啟動(dòng)MAC層的輸出,最后將數(shù)據(jù)發(fā)送出去.應(yīng)用層程序通過uip-udp-new()函數(shù)建立一個(gè)新的UDP連接,動(dòng)態(tài)分配一個(gè)未使用的本地端口號(hào),可以在使用uip-udp-new后調(diào)用uip-udp-bind()函數(shù)來選擇使用其他端口號(hào)[9].具體為:
uip-ipaddr-t addr;
struct uip-udp-conn*c;
uip-ipaddr(&addr,192,168,2,1);
c=uip-udp-new(&addr,UIP-HTONS(12345));
if(c!=NULL)
{uip-udp-bind(c,UIP-HTONS(12344));
}
struct uip-udp-conn*uip-udp-new
(
const uip-ipaddr-t*ripaddr,
uint16-t rport
);
本設(shè)計(jì)主要實(shí)現(xiàn)了LJ601[10]網(wǎng)關(guān),其將6LoWPAN網(wǎng)絡(luò)和互聯(lián)網(wǎng)互聯(lián)在一起,運(yùn)行有IPv4和IPv6雙棧.此網(wǎng)關(guān)有2個(gè)口:一個(gè)是WAN口,另一個(gè)是LAN口.WAN口可以直接連接到互聯(lián)網(wǎng).本設(shè)計(jì)采用WAN口,所有的6LoWPAN節(jié)點(diǎn)都共享這單一的WAN口,其測(cè)試平臺(tái)的結(jié)構(gòu)如圖5所示.測(cè)試中,通過Contiki對(duì)節(jié)點(diǎn)和網(wǎng)關(guān)分配地址:節(jié)點(diǎn)IPv6地址為2001::1/64,其網(wǎng)關(guān)缺省IPv6地址為2001::1,Window 7 PC IPv6地址為2001::6/64.為了測(cè)試其連通性,6LoWPAN傳感器節(jié)點(diǎn)使用PING命令,測(cè)試結(jié)果如圖6所示.
圖5 6LoWPAN測(cè)試平臺(tái)
圖6 6LoWPAN PING測(cè)試結(jié)果
本研究設(shè)計(jì)了一個(gè)網(wǎng)關(guān),并采用Contiki操作系統(tǒng)實(shí)現(xiàn)6LoWPAN節(jié)點(diǎn)和IPv6互聯(lián)網(wǎng)的互操作,連通性測(cè)試結(jié)果表明,外部互聯(lián)網(wǎng)可以使用IPv6協(xié)議完成和內(nèi)部無線網(wǎng)絡(luò)的全I(xiàn)P連接,這對(duì)于實(shí)現(xiàn)互聯(lián)網(wǎng)及物聯(lián)網(wǎng)的互操作和集成有一定的指導(dǎo)意義.
[1]Montenegro G,Kushalnagar N,Hui J,et al.TransmissionofIPv6packetsoverIEEE802.15.4networks,RFC4944[EB/OL].[2015-10-14].http://data tracker.ietf.org/doc/rfc4944.
[2]Dunkels A,?sterlind F,He Zhitao.Anadaptivecommunicationarchitectureforwirelesssensornetworks[C]//Proceedingsofthe5thInternationalConferenceonEmbeddedNetworkedSensorSystem,2007.Sydney,Australia:ACM Press,2007.
[3]Zimmermann Andre,Silva J S,Sobral J B,et al.6GLAD:IPv6globaltolink-layerAddresstranslationfor6LoWPANoverheadreducing[C]//NextGenerationInternetNetwork,2008.Krakow,Poland:IEEE Press,2008.
[4]Hossen M S,Kabir AFM S,Khan R H,et al.Interconnectionbetween802.15.4devicesandIPv6:Implicationsandexitingapproaches[J].Int J Comp Sci Iss,2010,7(1):19-31.
[5]Choi D I,Kim M S,Park C U,et al.Anefficientglobalcommunicationmethodfor6LoWPAN[J].Int J Inf,2012,15(5):1949-1960.
[6]Campos B D S,Rodrigues J J P C,Mendes L D P,et al.DesignandconstructionofwirelesssensornetworkgatewaywithIPv4/IPv6support[J].Wirel Sens Netw,2011,57(4):1-5.
[7]劉嘉宇,高德云.基于Contiki OS的低功耗無線傳感器網(wǎng)絡(luò)節(jié)點(diǎn)設(shè)計(jì)[J].計(jì)算機(jī)與現(xiàn)代化,2015,31(3):122-126.
[8]朱曉榮,李鳳國.基于Contiki的6LoWPAN適配層的研究與實(shí)現(xiàn)[J].信息通信技術(shù),2013,7(3):66-70.
[9]張巖.基于Contiki系統(tǒng)的物聯(lián)網(wǎng)應(yīng)用平臺(tái)設(shè)計(jì)與實(shí)現(xiàn)[D].哈爾濱:哈爾濱工程大學(xué) 2013.
[10]聞志平,李迅,李洪峻.無線傳感器網(wǎng)絡(luò)IPv6接入系統(tǒng)的設(shè)計(jì)與實(shí)現(xiàn)[J].計(jì)算機(jī)工程,2010,36(3):109-111.
Abstract:Wireless sensor network(WSN) is one of the important parts of the Internet of Things,which mainly detects the outside environment through sensors and passes the measurement parameters to the server through wireless medium.The sensor nodes can be connected together to form the data network routing.The traditional IP protocol stack is not suitable for wireless sensor nodes because of its limited resources and energy.6LoWPAN technology is mainly used to complete the conversion between IPv6 Internet and WSN protocol and data.By introducing the Contiki operating system and the appropriate IPv6 protocol stack between the sensor nodes and the embedded gateway,the interconnection between WSN and the Internet can be well implemented.In this paper,the uIP protocol stack of CC2530 gateway based on Contiki is implemented,and the UDP communication protocol is designed.The test environment is set up according to the design scheme,and the connectivity test is carried out by using the PING command.
Keywords:6LoWPAN;IPv6;Internet;connectivity
ResearchonConnectivityBetween6LoWPANSubsetinWirelessSensorNetworkandInternetBasedonContiki
TIELing1,RENHaibo2
(1.School of Information Science and Engineering, Chengdu University, Chengdu 610106,China;2.Shijihuaning Technology Co., Ltd., Chengdu 610041, China)
TP311.52;TN929.532
A
1004-5422(2017)03-0262-03
2017-07-12.
四川省科技廳自然科學(xué)基金(2013GZ0016)資助項(xiàng)目.
鐵 玲(1970 — ), 女, 博士, 副教授, 從事物聯(lián)網(wǎng)與信息安全研究.