Abstract
With the advancement of IPv6 technology, many nodes in wireless sensor networks realize seamless connections with the Internet via IPv6 addresses. Security issues are a significant obstacle to the widespread adoption of IPv6 technology. Resource-constrained IPv6 nodes face dual attacks: local and Internet-based. Moreover, constructing an active cyber defense system for IPv6-based wireless sensor networks is difficult. In this article, we propose a
Introduction
In recent years, the scale of wireless sensor networks (WSNs) has grown rapidly. Internet of Things (IoT) systems have many types of networks connecting various system entities. Different networks need to be combined to provide the necessary network connectivity between the entities attached to each network. Entities must be interoperable to operate seamlessly in different networks. However, currently available heterogeneous network protocols in WSNs are typically application-specific. Network-level solutions are required among WSNs and between wired and wireless networks to provide seamless communications and interactions among different network types. IPv6 facilitates information exchange, peer-to-peer connectivity, and seamless communication between different IoT systems.
IPv6 technology can have a large number of address resources, automatic address configuration, and good mobility. The use of IPv6 technology in WSNs is inevitable, especially when nodes in WSNs are required to connect to the Internet using IPv6 technology seamlessly.
Numerous standardization work has been completed in Internet Engineering Task Force (IETF) to enable the use of IPv6 technology in WSNs. For IPv6 communication on IEEE 802.15.4 devices, IETF proposed IPv6 over low-power wireless personal area networks (6LoWPANs). These documents focus on the standardization of the IPv6 head compression, 1 neighbor discovery, 2 time-slotted channel hopping (TSCH), 3 and so on.
WSN features and frameworks have been significantly changed because of access to the Internet via IPv6 technology, which may lead to new network threats and attacks. Moreover, the WSN is in an unknown environment with limited resources and hidden attacks. 4 Therefore, it is necessary to study the security issues of IPv6-based WSNs.
Intrusion detection is a mechanism that detects network attacks by analyzing activities in a network or system. 5 Once an attack is detected, an intrusion detection system (IDS) records relevant information about the attack. However, current intrusion detection mechanisms against multiple attacks support multiple protocols but are still in development stages. Therefore, an intrusion detection mechanism, considering the overall security of IPv6-based WSNs, should be investigated further.
The contributions of this article are as follows:
A common intrusion detection framework for IPv6-based WSNs is developed. Based on this framework, a security framework consisting of an intrusion detection console as the core, a traffic generation module, a traffic capture module, a feature processing module, and an intrusion detection module is proposed, and the coordination mechanism and workflow of each module are designed.
Methods of collecting and processing security feature data are described for IPv6-based Internet and IPv6-based wireless networks. The IPv6-based WSNs features for intrusion detection are specified in this article. A set of lightweight intrusion detection algorithms based on
A test platform is developed to verify the proposed mechanism. The laboratory 6LoWPAN node and gateway are used to build an IPv6-based WSN and verify the proposed mechanism’s feasibility on the IPv6-based wireless. Compared with other schemes, the proposed mechanism can effectively reduce the false positive rate (FPR) of intrusion detection and achieves good detection efficiency and ACC.
This article is organized as follows. Section “Related work” reviews several existing works related to security and IDSs for WSNs. Section “Intrusion detection framework” describes the intrusion detection framework. Section “Intrusion detection mechanism” proposes a lightweight intrusion detection algorithm for IPv6-based WSNs based on KNN. Section “Verification and result analysis” develops a test platform to verify the proposed mechanism, and research results are analyzed and discussed. Finally, in section “Verification and result analysis,” we conclude the study with a summary.
Related work
Research on the security of Internet protocol (IP)-based WSNs has attracted much attention. In terms of standardization, IPv6 has supported Internet protocol security (IPsec) for WSNs. In 2020, RFC 5570 6 proposed an optional method for encoding packet sensitivity labels on IPv6 packets. The encoding provided multilevel network security services for network layer traffic in IPv6 environments. RFC 8750 7 updated an encapsulated security payload to generate a nonce using values provided in the encapsulating security payload sequence number to avoid sending initialization vector. RFC 4301 8 updated security architecture for IP. In 2019, RFC 8598 9 proposed two configuration payload attribute types for Internet key exchange protocol version 2 (IKEv2), adding support for private domain name system (DNS) domains.
Meanwhile, IP-based wireless sensor networks are usually resource-constrained mainly because nodes are attacked locally and on the Internet. Therefore, lightweight security mechanisms are necessary in this regard. Cao et al. 10 designed a lightweight security D2D (Device to Device) system using multiple sensors on mobile devices. In the research by Raza and Magnússon, 11 a lightweight IKE was proposed, and IKEv2 was adapted.
An active defense system can monitor a network and respond to detected attacks in real-time. Therefore, it is necessary to develop an active defense system for IPv6-based WSNs to deal with security issues and detect attacks in real-time.
There are several research studies on IDSs for specific attacks. In 2013, Shahid first proposed the IDS SVELTE 12 for routing attacks by changing routing information 13 against IPv6 WSNs, with intrusion detection using the widely used and accepted the opnet 14.5 simulators to simulate in turn WSN generation of data sets for normal flow and attack flow. Althubaity et al. 14 proposed a hybrid specification-based IDS to protect the RPL (IPv6 routing protocol for low-power and loss networks) topology in 6TiSCH networks from any manipulation on the rank value to establish rank attack or on the routing metric to perform rank attack based on the objective function. Amaran and Mohan 15 proposed Optimal Multilayer Perceptron (OMLP) with Dragonfly Algorithm (DA) for intrusion detection in WSN. The OMLP model has high accuracy and detection rate. Choudhary and Taruna 16 proposed a technique which is based on the frequency analysis onsite to find intrusion into the network; the data from these dedicated sensors are stored in a fuzzy analytical engine for inference. Jiang et al. 17 proposed SLGBM, an intrusion detection method for wireless sensor networks. A LightGBM algorithm is utilized to detect different network attacks. Sharma et al. 18 proposed a supervised machine learning-based IDS for RPL-based cyber–physical systems, that is capable of detecting several attacks.
Similarly, there are some research studies on IDSs for specific protocols. Moustafa et al. 19 proposed an integrated intrusion detection technology. Message queuing telemetry transport (MQTT) protocols are used in IoT systems, and the AdaBoost ensemble learning method was developed using decision tree (DT), naive Bayesian, and artificial neural networks (ANNs). Verma and Ranga 20 used an ensemble learning-based network IDS framework to detect routing attacks on the IPv6-based routing protocols for low-power and lossy networks. Shen et al.21–23 proposed IDSs for malware, which can suppress malware diffusion in IoT network. Zhou et al. 24 proposed a malware detection model based on game theory in WSNs. Liu et al.25–28 proposed a series of methods for virtual resource security detection in sensor edge cloud.
Existing research studies focus on specific protocols or attacks, and they can achieve effective intrusion detection. However, an intrusion detection mechanism, considering the overall security of IPv6-based WSNs, merits further investigation. Furthermore, the intrusion detection mechanism should be designed considering all IPv6-based WSN frameworks.
Intrusion detection framework
Traditional WSNs are typically stand-alone, not connected to any other external networks. They are usually composed of low-power, lossy networks, and many resource-constrained nodes, forming a closed wireless mesh network. To use IPv6 technology in WSNs, IETF proposed a 6LoWPAN protocol stack based on IEEE 802.15.4. The protocol stack has six layers, where its bottom layer adopts the IEEE 802.15.4 standards of the PHY and MAC layers. For implementing a seamless connection between the MAC and network layers, an adaption layer is added between the MAC and network layers to handle header compression, fragmentation, reassembly, and mesh route forwarding.
6LoWPAN nodes and gateways form an IPv6-based WSN through the 6LoWPAN protocol stack. When one or more gateways of the IPv6-based WSN access the Internet, an extended IPv6-based WSN forms. The network is connected to the intrusion detection console to form an intrusion detection framework. Figure 1 shows the IPv6-based WSN intrusion detection framework, including the intrusion detection console, the IPv6-based Internet side, and the IPv6-based wireless side.

IPv6-based WSN intrusion detection framework.
For the IPv6-based Internet side, a normal server and a malicious server can generate an original packet, and the traffic generated by the servers constitutes normal and abnormal activities. The traffic sent by the servers is forwarded to a PC or a portable device via a router.
For the IPv6-based wireless network side, each IPv6-based node forwards a packet to an IPv6-based border router through the IPv6-based route node, and finally, the IPv6-based border router uploads it to the gateway. Each node is configured with the CoAP/MQTT protocol and is connected to the gateway via the CoAP/MQTT proxy. An intrusion detection device is a tool for constructing and collecting security feature data for the intrusion detection mechanism. It can sniff packets from its neighbors and construct security feature packets.
The intrusion detection console logically includes five functional modules: a traffic generation module, traffic capture module, feature processing module, intrusion detection module, and intrusion response module. Their specific functions are as follows:
Traffic generation module: the traffic generation module includes a server on the IPv6-based Internet side and a sensor node on the IPv6-based wireless network side. These devices are responsible for generating original packets for intrusion detection.
Traffic capture module: the traffic capture module includes packet capture tools in the intrusion detection console and intrusion detection devices. The IPv6-based Internet side captures the traffic of an ingress router, and the IPv6-based wireless network side captures the security feature packets forwarded by the gateway to the Internet.
Feature processing module: the feature processing module is a feature extraction tool in the intrusion detection console. After capturing the original traffic, it is stored in a local database in the intrusion detection console. Feature extraction tools and feature processing algorithms help realize feature statistics and selection.
Intrusion detection module: the intrusion detection module stores processed feature data in a CSV (comma-separated values) file in the intrusion detection console, using it as an input to the intrusion detection module. This module trains the intrusion detection mechanism to form the normal profile (NP) of the intrusion detection model. The NP is used to detect and classify the real-time flow data into normal flow or abnormal flow in real-time.
Intrusion response module: the intrusion response module prevents organizational attacks by managing the network, such as taking malicious nodes offline or restoring normal network behaviors.
Intrusion detection mechanism
In this section, an intrusion detection mechanism is proposed for an IPv6-based WSN based on KNN. Figure 2 shows its specific workflow.

Intrusion detection mechanism workflow.
Three steps are involved in the proposed intrusion detection mechanism:
Security feature data collection and processing: on the IPv6-based Internet side, original packets generated by the gateway are collected and stored in the database. On the IPv6-based wireless network side, the intrusion detection device constructs a security feature message and eventually forwards it to the gateway. The packet capturing tool captures the packet from the gateway and stores it in the database. The feature processing module will perform feature extraction on packets stored in the local database to generate traffic features and generate security feature data after performing statistics on the traffic features.
Data standardization and feature selection: the feature processing module standardizes security feature data and uses feature selection algorithms to screen appropriate security features. Finally, the feature processing module creates a security feature data set for training the intrusion detection algorithms.
Algorithm training and intrusion detection: the intrusion detection module trains the algorithm, generating an intrusion detection model. In addition, the intrusion detection module needs to be regularly updated to adapt to network changes. The intrusion detection module also detects new security feature data. When the detected traffic flow is abnormal, the intrusion response module is responsible for processing the abnormal node.
Security feature data collection and processing
The network traffic on the IPv6-based Internet side uses a packet capturing tool to capture original packets of the entry router to form a packet capture (pcap) file. The pcap file needs to be processed to generate a record for each message sent and received. Implicit information related to normal and abnormal activities is recorded. Those records are further processed and transformed into security feature data for online analysis by the intrusion detection algorithm. IPv6-based Internet side security features are divided into HTTP-based features, traffic-based features, and transaction-based features. Table 1 shows the HTTP-based features, Table 2 shows the traffic-based features, and Table 3 shows the IPv6-based Internet side transaction-based features.
HTTP-based features.
RTT: round trip time.
Internet side traffic-based features.
IP: Internet protocol.
Internet side transaction-based features.
The IPv6-based wireless network side security features include RPL-based features, application layer-based features, 6top-based features, transaction-based features, and TSCH-based features.Table 4 shows the RPL-based features, Table 5 shows the application layer-based features, Table 6 shows the TSCH-based features, Table 7 shows the 6top-based features, and Table 8 shows the transaction-based features.
RPL-based features.
DAO: Destination Advertisement Object; DIO: Destination Oriented Directed Acyclic Graph Information Object.
Application layer-based traffic features.
TSCH-based features.
6top-based features.
IPv6-based WSN side transaction-based features.
Application layer-based features include IP address and the port numbers of a source and destination and protocol. Transaction-based features are generated based on the interaction of flow identifiers created in a time window to maintain online detection of malicious activities. This includes traffic statistics, such as the number of connections in a fixed period. A flow identifier and session time are sequentially stored by the packet capturing tool after obtaining the header information of the original packet. According to the time-stamp of the captured packets, the packets are grouped and processed in a fixed collection cycle to generate traffic features in the collection cycle.
Feature data standardization and feature selection
The generated security feature data set is denoted by
Standardization
Box–Cox transformation
Correlation analysis and machine learning algorithms have a default requirement that data follow the normal distribution. However, in reality, data seldom follow the normal distribution.
Box–Cox transformation can reduce unobservable errors and predict the correlation of variables to a certain extent. Therefore, before performing the feature correlation analysis, we use the Box–Cox transformation to bring the data as close to the normal distribution as possible
It can be seen from equation (3) that the final form of Box–Cox transformation is determined by
When
When
When
Kolmogorov–Smirnov test
Kolmogorov–Smirnov test 29 is used to determine the normal distribution of features. It involves the degree of consistency between the eigenvalue distribution and the completely theoretical continuous distribution.
Equation (4) is the cumulative distribution function
Equation (5) is the Kolmogorov distribution function
Feature correlation analysis
Correlation analysis is a statistical evaluation technique used to determine the relationship between features. This technique is used to study the relationship between the features of the training set and test set.
Pearson’s correlation coefficient
Pearson’s correlation coefficient (PCC) is used to study feature correlation between the training set and test set, without considering labels or categories. PCC is a measure of the strength and direction of the linear correlation between two features.
Equation (6) is the PCC between features
In equation (6),
The calculated value of PCC can vary from +1 to 0 to −1. A positive value of PCC indicates that two features are positively related, whereas a negative value of PCC indicates that two features are negatively related.
Gain ratio
The gain ratio is used to classify the correlation between features, and it considers the corresponding instance labels. The analysis aims to find features that distinguish between normal traffic instances and attack traffic instances.
Splitting information is the potential information generated by splitting the security feature data set
In equation (7),
The average information entropy required to classify an instance is expressed in equation (8)
In equation (8),
Based on the feature
Therefore, the information gain before and after splitting can be calculated using equation (10)
The gain ratio is defined as the ratio between the information gain and split information
Intrusion detection algorithm
The proposed intrusion detection algorithm proposed is an anomaly detection method for a single classification problem. It is a variant of the KNN algorithm, which aims to solve the shortcomings of the KNN algorithm with high computation and lazy learning. In IPv6-based WSN intrusion detection, the intrusion detection algorithm needs to distinguish between normal traffic and abnormal traffic. The key assumption of the proposed intrusion detection algorithm is that normal data points appear in dense neighborhoods and abnormal data points are far from neighbors.
Quantification method of grid structure
Each data object is quantified into a
For the data dimension

The intrusion detection hypercube grid structure.
In 2D space, the length of the grid is
The grid structure has the following geometric properties:
The distance between any data objects in a grid is at most
Algorithm training
The training process of the intrusion detection algorithm involves using the generated security feature data set to adjust the parameters of the algorithm (a KNN classifier) to meet the requirements of intrusion detection. The proposed intrusion detection algorithm analyzes the relationship between the data and the label in the security feature data set. Thus, the algorithm can learn to infer the affiliation of new data. In the training process, the security feature data are projected into the grid structure.
The maximum and minimum values of the
If the training data remain unchanged, the boundary can be fixed. However, the IDS needs to update the training data regularly while retraining the model. Therefore, it is necessary to set aside appropriate redundant space and leave a margin at the current boundary for the online update, the grid structure can then capture data outside the current boundary.
In addition, the coefficient
For the hypercube position in which the data
Intrusion detection
Equation (14) is defined as the alternative detection area of test data. The alternative detection area is shown in Figure 3
The intrusion detection rules are described as follows:
If there are at least
If the data points in the grid are less than
If the data in DR are less than
Verification and result analysis
This section describes the test platform for verifying and analyzing the intrusion detection mechanism. Figure 4 shows the test platform, which is built with an IPv6-based WSN platform independently developed by our laboratory. The platform has obtained the IPv6 Ready Phase-2 Logo, which designates the consistency of the IPv6 protocol and device interoperability. The platform includes one PC, one 6LoWPAN gateway, and fifteen 2.4 GHz band 6LoWPAN nodes.

Intrusion detection mechanism test platform.
The UNSW-NB15 30 data set is used as the feature data set of the IPv6-based Internet side. The raw network packets of the UNSW-NB15 data set were created using the IXIA PerfectStorm tool in the Cyber Range Lab of the Australian Centre for Cyber Security for generating a hybrid of real modern normal activities and synthetic contemporary attack behaviors.
The 6TiSCH Simulator
31
is used to simulate normal activities and attack behaviors of IPv6-based nodes. After the simulation, a DAT file is generated as the feature data set of the IPv6-based wireless network side. The simulation has 50 nodes, 5
Data set analysis
The security feature data set is divided into training data set and test data set. The skewness, kurtosis, and PCC of the data set are analyzed.
Figure 5 shows the skewness of IPv6-based wireless network side data set. In the training data set, features 20, 23, 25, 33, 39, 40, and 42 are positively skewed, and features 39 and 41 are negatively skewed. The training data set and the test data set have almost equal skewness, and it can be inferred that they have similar distributions.

Skewness of feature data set.
Figure 6 shows the kurtosis of IPv6-based wireless network side data set. Most of the features of the training data set and the test data set have flat kurtosis. Features 19, 20, 38, 40, 42, and 43 have positive kurtosis. The training data set and the test data set have similar kurtosis.

Kurtosis of feature data set.
The PCC of IPv6-based wireless network side data set is shown in Figure 7, most of the correlations between the features remain balanced, there is no excessive correlation, and no correlation, such features are acceptable features. Acceptable-related features account for more than 70%, and the data set has good correlation.

PCC of feature data set.
Overhead analysis
The intrusion detection algorithm should be as light as possible to ensure that it can maintain optimal network performance when used in a resource-constrained environment such as IPv6-based WSNs. Therefore, the overhead of the intrusion detection algorithm is evaluated. Assume that retraining the algorithm necessitates
Computational complexity
Computational complexity determines the detection efficiency of an algorithm. The intrusion detection algorithms mainly include training the algorithm and intrusion detection, both of which are completed in the intrusion detection console.
The computational complexity of projecting each training data to the hypercube is
In the detection process, each data will generate computational complexity from
The results show that the computational complexity of each function varies linearly or logarithmically with the number of data
Communication overhead
The communication overhead generated during the detection process mainly includes the feature data collected by the intrusion detection device and sent to the gateway and the intrusion response.
A packet payload sent by the intrusion detection device to the gateway is 4 bytes. The feature data sending period is
During the intrusion response process, the offline command message length is 14 bytes, and the broadcast offline message length is 12 bytes. In a training cycle, the communication overhead of the feature data is 4
Storage overhead
Since feature data of the IPv6-based WSN changes constantly, the NP of the intrusion detection model changes accordingly, and the NP is updated online. Therefore, the intrusion detection console stores only the NP, the length of the position-coding unit is
Performance analysis
First, the feasibility of the intrusion detection mechanism is verified. When an attacking node is detected, the intrusion detection console records the device address of the attacking node in an offline command message. Then, it sends a message to the gateway to take the attacking node offline and then broadcasts the node’s offline information to other nodes to update the network topology.
The algorithm’s intrusion detection performance and efficiency were evaluated in terms of ACC, the FPR, receiver operating characteristic (ROC) curve, and CPU running time. ACC is the percentage of all normal and abnormal records that are correctly detected. FPR is the percentage of incorrectly identified abnormal records. The ROC curve represents the relationship between the true positive rate (TPR) and FPR, reflecting the algorithm’s overall performance. scikit-learn 32 is a Python module comprising a wide range of state-of-the-art machine learning algorithms for medium-scale supervised and unsupervised problems. We compared the proposed model’s performance to intrusion detection models trained on this study’s feature data using DT, 33 ANN, 34 random forest (RF), 35 KNN, 36 AdaBoost, 37 logistic regression (LR), and Bayesian algorithms; 38 these algorithms are from scikit-learn.
Two experiments were conducted to verify the intrusion mechanism’s performance further. In both experiments, the security feature dimension was
Experiment 1 was conducted for preliminary verification of intrusion detection performance. The coefficient

Results of Experiment 1 (a) ROC curve and (b) detection time.
Experiment 2 tests the robustness of intrusion detection capability and compares and analyzes it with other algorithms. The length of the grid
Figure 9 shows the experimental results in terms of ACC except for the sixth experiment. The results show that ACC is stable at approximately 90%, which shows the algorithm’s effectiveness. The ACC of the proposed algorithm proposed close to DT, AdaBoost, and RF and better than most of the comparison algorithms.

ACC comparison.
Figure 10 shows the experimental results in terms of FPR. The proposed algorithm results are close to those of DT, AdaBoost, and RF. It does not exceed 25% and can even achieve 6% FPR, which is better than most comparison algorithms. The FPR indicates that the NP has well expressed the behaviors of nodes in the network, and the algorithm is robust.

FPR comparison.
The experimental results in terms of detection time are shown in Figure 11. The results of the proposed algorithm proposed are close to those of the LR, DT, and RF algorithms. It can achieve timely detection within 2 ms.

Detection time comparison.
Experiment 1 and Experiment 2 results show that the proposed intrusion detection algorithm’s AUC is 0.87 and ACC is stable around 0.9, which indicates that the classifier has a good learning effect and effective intrusion detection. The proposed algorithm’s FPR is less than 0.25, which indicates that the NP well expressed the behaviors of nodes in the WSN. The algorithm’s detection time of a single sample is stable within 0.12–0.14 ms. The overall detection time of the algorithm is stable within 2 ms, indicating that the algorithm is highly efficient. In addition, the detection time of the intrusion detection mechanism meets the requirement of timely detection.
Analysis and experimental results show that the algorithm proposed in this research can effectively reduce the FPR of intrusion detection, achieving good detection efficiency and ACC. In addition, the inexpensiveness of the intrusion detection mechanism allows for the realization of the real-time detection of malicious attacks in IPv6-based WSNs. The proposed intrusion detection algorithm can achieve better detection performance than other comparison algorithms.
Conclusion and future work
This research proposed an intrusion detection framework and mechanism for an IPv6-based WSN. The mechanism is lightweight and efficient, and the NP of the intrusion detection model is trained using the feature data set. The intrusion detection algorithm uses the NP to perform real-time detection of traffic data to achieve rapid detection after a significant number of devices are connected in the network. In addition, a test platform was developed to verify the effectiveness and performance of the intrusion detection mechanism. Experimental results have shown that implementing the proposed intrusion detection mechanism is reasonable and can be used in IPv6-based WSNs.
The intrusion detection mechanism can only detect active threats; it cannot detect threats in advance. Furthermore, in the face of fake malicious behavior, the attack (threat) source cannot be traced, resulting in some false positives. In the future, we will build the 6TiSCH platform to further verify the proposed intrusion detection mechanism. The intrusion detection algorithm will need to collaborate with expert systems to analyze security situations and prevent attacks in advance. Furthermore, more in-depth research on the nature of networks and attack mechanisms will be critical for developing a comprehensive intrusion detection mechanism.
Footnotes
Handling Editor: Yanjiao Chen
Declaration of conflicting interests
The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.
Funding
The author(s) disclosed receipt of the following financial support for the research, authorship, and/or publication of this article: This work is supported by The National Key Research and Development Program of China (2018YFB1702202) and The Chongqing Talent Plan Project (cstc2021ycjh-bgzxm0206).
