From 2f5e5e20ea984e7f1b2c6940ed6169b7a4bd9a36 Mon Sep 17 00:00:00 2001 From: Juha Heiskanen Date: Fri, 9 Apr 2021 17:39:01 +0300 Subject: [PATCH] Generic forwarding callback and EF state enabler for Wi-SUN BBR. --- source/6LoWPAN/adaptation_interface.c | 9 +++++++++ source/6LoWPAN/lowpan_adaptation_interface.h | 2 ++ source/6LoWPAN/ws/ws_bbr_api.c | 15 +++++++++++++++ source/6LoWPAN/ws/ws_bootstrap.c | 1 + source/Common_Protocols/ipv6.c | 3 +++ source/NWK_INTERFACE/Include/protocol.h | 1 + source/NWK_INTERFACE/protocol_core.c | 1 + .../unittest/stub/adaptation_interface_stub.c | 5 +++++ 8 files changed, 37 insertions(+) diff --git a/source/6LoWPAN/adaptation_interface.c b/source/6LoWPAN/adaptation_interface.c index bf389a2a5640..b78304c07858 100644 --- a/source/6LoWPAN/adaptation_interface.c +++ b/source/6LoWPAN/adaptation_interface.c @@ -1214,6 +1214,15 @@ static void lowpan_adaptation_priority_status_update(protocol_interface_info_ent } } +void lowpan_adaptation_expedite_forward_enable(protocol_interface_info_entry_t *cur) +{ + fragmenter_interface_t *interface_ptr = lowpan_adaptation_interface_discover(cur->id); + if (!interface_ptr) { + return; + } + lowpan_adaptation_high_priority_state_enable(cur, interface_ptr); +} + void lowpan_adaptation_interface_slow_timer(protocol_interface_info_entry_t *cur) { fragmenter_interface_t *interface_ptr = lowpan_adaptation_interface_discover(cur->id); diff --git a/source/6LoWPAN/lowpan_adaptation_interface.h b/source/6LoWPAN/lowpan_adaptation_interface.h index 30eb284552af..761428a83d5c 100644 --- a/source/6LoWPAN/lowpan_adaptation_interface.h +++ b/source/6LoWPAN/lowpan_adaptation_interface.h @@ -62,6 +62,8 @@ int8_t lowpan_adaptation_free_messages_from_queues_by_address(struct protocol_in int8_t lowpan_adaptation_indirect_queue_params_set(struct protocol_interface_info_entry *cur, uint16_t indirect_big_packet_threshold, uint16_t max_indirect_big_packets_total, uint16_t max_indirect_small_packets_per_child); +void lowpan_adaptation_expedite_forward_enable(struct protocol_interface_info_entry *cur); + void lowpan_adaptation_interface_slow_timer(struct protocol_interface_info_entry *cur); #endif /* LOWPAN_ADAPTATION_INTERFACE_H_ */ diff --git a/source/6LoWPAN/ws/ws_bbr_api.c b/source/6LoWPAN/ws/ws_bbr_api.c index 441a819ad637..1fc5a5940c3e 100644 --- a/source/6LoWPAN/ws/ws_bbr_api.c +++ b/source/6LoWPAN/ws/ws_bbr_api.c @@ -38,11 +38,13 @@ #include "RPL/rpl_data.h" #include "Common_Protocols/icmpv6.h" #include "Common_Protocols/icmpv6_radv.h" +#include "Common_Protocols/ip.h" #include "ws_management_api.h" #include "net_rpl.h" #include "Service_Libs/nd_proxy/nd_proxy.h" #include "6LoWPAN/ws/ws_bbr_api_internal.h" #include "6LoWPAN/ws/ws_pae_controller.h" +#include "6LoWPAN/lowpan_adaptation_interface.h" #include "DHCPv6_Server/DHCPv6_server_service.h" #include "DHCPv6_client/dhcpv6_client_api.h" #include "libDHCPv6/libDHCPv6_vendordata.h" @@ -907,6 +909,18 @@ bool ws_bbr_ready_to_start(protocol_interface_info_entry_t *cur) return true; } +static void ws_bbr_forwarding_cb(protocol_interface_info_entry_t *interface, buffer_t *buf) +{ + uint8_t traffic_class = buf->options.traffic_class >> IP_TCLASS_DSCP_SHIFT; + + if (traffic_class == IP_DSCP_EF) { + //indicate EF forwarding to adaptation + lowpan_adaptation_expedite_forward_enable(interface); + } +} + + + void ws_bbr_init(protocol_interface_info_entry_t *interface) { (void) interface; @@ -919,6 +933,7 @@ void ws_bbr_init(protocol_interface_info_entry_t *interface) ws_bbr_fhss_bsi = ws_bbr_bsi_read(&bbr_info_nvm_tlv); tr_debug("Read BSI %u from NVM", ws_bbr_fhss_bsi); } + interface->if_common_forwarding_out_cb = &ws_bbr_forwarding_cb; } diff --git a/source/6LoWPAN/ws/ws_bootstrap.c b/source/6LoWPAN/ws/ws_bootstrap.c index df5d09a7241e..2a04826a833b 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.c +++ b/source/6LoWPAN/ws/ws_bootstrap.c @@ -1214,6 +1214,7 @@ static int8_t ws_bootstrap_down(protocol_interface_info_entry_t *cur) ws_pae_controller_stop(cur); ws_bootstrap_candidate_table_reset(cur); blacklist_clear(); + cur->if_common_forwarding_out_cb = NULL; return nwk_6lowpan_down(cur); } diff --git a/source/Common_Protocols/ipv6.c b/source/Common_Protocols/ipv6.c index 7a4d6030a466..045e6c471c34 100644 --- a/source/Common_Protocols/ipv6.c +++ b/source/Common_Protocols/ipv6.c @@ -1362,6 +1362,9 @@ buffer_t *ipv6_forwarding_up(buffer_t *buf) } } else { /* unicast */ if (!for_us) { + if (cur->if_common_forwarding_out_cb) { + cur->if_common_forwarding_out_cb(cur, buf); + } return ipv6_consider_forwarding_unicast_packet(buf, cur, &ll_src); } } diff --git a/source/NWK_INTERFACE/Include/protocol.h b/source/NWK_INTERFACE/Include/protocol.h index 6350cb7d3ea8..0ca9c30a655f 100644 --- a/source/NWK_INTERFACE/Include/protocol.h +++ b/source/NWK_INTERFACE/Include/protocol.h @@ -474,6 +474,7 @@ struct protocol_interface_info_entry { int8_t (*if_down)(struct protocol_interface_info_entry *cur); int8_t (*if_up)(struct protocol_interface_info_entry *cur); void (*if_stack_buffer_handler)(buffer_t *); + void (*if_common_forwarding_out_cb)(struct protocol_interface_info_entry *, buffer_t *); bool (*if_ns_transmit)(struct protocol_interface_info_entry *cur, ipv6_neighbour_t *neighCacheEntry, bool unicast, uint8_t seq); bool (*if_map_ip_to_link_addr)(struct protocol_interface_info_entry *cur, const uint8_t *ip_addr, addrtype_t *ll_type, const uint8_t **ll_addr_out); bool (*if_map_link_addr_to_ip)(struct protocol_interface_info_entry *cur, addrtype_t ll_type, const uint8_t *ll_addr, uint8_t *ip_addr_out); diff --git a/source/NWK_INTERFACE/protocol_core.c b/source/NWK_INTERFACE/protocol_core.c index 7c499586eaae..45f0c413841a 100644 --- a/source/NWK_INTERFACE/protocol_core.c +++ b/source/NWK_INTERFACE/protocol_core.c @@ -462,6 +462,7 @@ static void protocol_core_base_init(protocol_interface_info_entry_t *entry, nwk_ entry->ipv6_configure = NULL; entry->if_lowpan_security_params = NULL; entry->if_ns_transmit = NULL; + entry->if_common_forwarding_out_cb = NULL; entry->if_special_forwarding = NULL; entry->if_snoop = NULL; entry->if_icmp_handler = NULL; diff --git a/test/nanostack/unittest/stub/adaptation_interface_stub.c b/test/nanostack/unittest/stub/adaptation_interface_stub.c index 6c58db062127..5b24965c60c3 100644 --- a/test/nanostack/unittest/stub/adaptation_interface_stub.c +++ b/test/nanostack/unittest/stub/adaptation_interface_stub.c @@ -116,3 +116,8 @@ void lowpan_adaptation_interface_slow_timer(protocol_interface_info_entry_t *cur { } + +void lowpan_adaptation_expedite_forward_enable(struct protocol_interface_info_entry *cur) +{ + +}