通过对 Cooja 中 PowerTracker 的观察,我在 Cooja 模拟器中的 Z1 节点似乎接收到了它们可以获得的所有数据包(在范围内)。我正在使用带有 CSMA 的 nullnet。我怎么能让我的 Z1 节点拒绝不适合他们的消息(帧)?
Cooja 仿真配置屏幕截图 - DGRM 无线电环境
在这里,我排列了四个 Z1 节点:节点 1、节点 2、节点 3 和节点 4,它们的链路层地址分别为0100.0000.0000.0000
、0200.0000.0000.0000
、0300.0000.0000.0000
、0400.0000.0000.0000
。只有两个相邻的节点可以相互通信(如上图所示,这些配置是通过DGRM链路设置来实现的)。
初始化完成后,所有节点会分别广播一条消息,确认自己的存在;然后,节点 1 将不再发送任何消息,节点 2、3 和 4 会定期将其消息单播到0600.0000.0000.0000
不存在的地址。
然后,一个绝望的场景发生了,CC2420有一个地址过滤器,当Z1节点发现传入的消息不是它的,它应该不再接收消息的左边部分。然而,在我们的例子中,来自 PowerTracker 的 Radio RX 时间如下:
Z1_1 MONITORED 719915550 us
Z1_1 ON 718993610 us 99.87 %
Z1_1 TX 768 us 0.00 %
Z1_1 RX 552061 us 0.08 %
Z1_1 INT 0 us 0.00 %
Z1_2 MONITORED 719915582 us
Z1_2 ON 719009242 us 99.87 %
Z1_2 TX 552829 us 0.08 %
Z1_2 RX 483012 us 0.07 %
Z1_2 INT 11 us 0.00 %
Z1_3 MONITORED 719938987 us
Z1_3 ON 719032647 us 99.87 %
Z1_3 TX 552864 us 0.08 %
Z1_3 RX 851568 us 0.12 %
Z1_3 INT 54522 us 0.01 %
Z1_4 MONITORED 719939019 us
Z1_4 ON 719043863 us 99.88 %
Z1_4 TX 552843 us 0.08 %
Z1_4 RX 479181 us 0.07 %
Z1_4 INT 4 us 0.00 %
CC2420 的过滤在 Cooja 中似乎死了,还是我犯了很大的错误?我怎么能让我的 Z1 节点拒绝不适合他们的消息(帧)?
下面是我的实验源代码,它是基于`Nullnet unicast example生成的。这些例子都是杰作,我只是在上面做些肤浅的改变:
#include "contiki.h"
#include "net/netstack.h"
#include "net/nullnet/nullnet.h"
#include <string.h>
#include <stdio.h>
#include "sys/log.h"
#define LOG_MODULE "App"
#define LOG_LEVEL LOG_LEVEL_INFO
/* Configuration */
#define SEND_INTERVAL (1 * CLOCK_SECOND)
/**
* For node 1 the dest_addr is 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00;
* Nodes 2, 3, and 4's are 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00;
*/
static linkaddr_t dest_addr = {{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
/*---------------------------------------------------------------------------*/
PROCESS(nullnet_example_process, "NullNet unicast example");
AUTOSTART_PROCESSES(&nullnet_example_process);
/*---------------------------------------------------------------------------*/
void input_callback(const void *data, uint16_t len, const linkaddr_t *src, const linkaddr_t *dest)
{
if (len == sizeof(unsigned))
{
unsigned count;
memcpy(&count, data, sizeof(count));
LOG_INFO("Received %u from ", count);
LOG_INFO_LLADDR(src);
LOG_INFO_("\n");
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(nullnet_example_process, ev, data)
{
static struct etimer periodic_timer;
static unsigned count = 0;
nullnet_set_input_callback(input_callback);
PROCESS_BEGIN();
/* Activate Address Filtering */
NETSTACK_RADIO.set_value(RADIO_PARAM_RX_MODE,RADIO_RX_MODE_ADDRESS_FILTER | RADIO_RX_MODE_AUTOACK);
/* Initialize NullNet */
nullnet_buf = (uint8_t *)&count;
nullnet_len = sizeof(count);
/* Acknowledgement of existence */
NETSTACK_NETWORK.output(NULL);
// Main loop
if (!linkaddr_cmp(&dest_addr, &linkaddr_node_addr))
{
/* Node 1 will not perform the following part. */
etimer_set(&periodic_timer, SEND_INTERVAL);
while (1)
{
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
LOG_INFO("Sending %u to ", count);
LOG_INFO_LLADDR(&dest_addr);
LOG_INFO_("\n");
// NETSTACK_NETWORK.output(NULL);
NETSTACK_NETWORK.output(&dest_addr);
count++;
etimer_reset(&periodic_timer);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
配置文件:
/************** system configuration ***************/
#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_
/* Configuration of ACK */
#define CSMA_CONF_SEND_SOFT_ACK 0 /* Disable software ACK */
#define CC2420_CONF_AUTOACK 1 /* Using AUTO_ACK from CC2420 */
#define CSMA_CONF_ACK_WAIT_TIME RTIMER_SECOND / 2500 /* Default */
#define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME RTIMER_SECOND / 1500 /* Default */
/* Configuration of Energest - Waring !Do not use it when using TSCH MAC! */
#define ENERGEST_CONF_ON 1 /* Activation */
#define SIMPLE_ENERGEST_CONF_PERIOD (CLOCK_SECOND * 2400) /* 2400 second */
// #define LOG_CONF_LEVEL_RPL LOG_LEVEL_WARN
// #define LOG_CONF_LEVEL_TCPIP LOG_LEVEL_WARN
// #define LOG_CONF_LEVEL_IPV6 LOG_LEVEL_WARN
// #define LOG_CONF_LEVEL_6LOWPAN LOG_LEVEL_WARN
// #define LOG_CONF_LEVEL_MAC LOG_LEVEL_WARN
// #define LOG_CONF_LEVEL_FRAMER LOG_LEVEL_WARN
#endif
此外,如果我的记忆是正确的,如果AUTO_ACK被激活,CC2420的Address_filtering也应该被激活。