Feature/refactor bacnet ipv4 add unit tests (#64)

* refactor BACnet/IPv4 BVLC into encode-decode library with unit tests
Added Read-Broadcast-Distribution-Table encoding and unit test.
Added Read-Broadcast-Distribution-Table-Ack encoding and unit test.
Added Read-Foreign-Device-Table-Ack encoding and unit test.
Added some BDT/FDT diff copy functions with unit tests
Added some FDT add and delete entry functions with unit tests
Added some BDT set append and clear entry functions with unit tests
Added some BIPv4 address conversion functions with unit tests
Added non-BBMD handling unit test
Added basic unit test for BBMD handler
Added BBMD broadcast mask get set and unit tests
Added IPv6 maintenance timer.
Added ReadFDT app
Fixed ReadBDT app
Added Who-Is to Makefile for individual app build
Fixed debugging code blocks projects by swapping bip.c for h_bbmd.c module.
Ported BACnet/IPv4 to refactored BVLC for Linux, BSD, Windows
Fix datalink debug for DLENV module
Improve BIPv4 linux driver debug info
Added BDT mask functions
Reduce debug info clutter in Who-Is app by using environment option
Fix TTL seconds upper bounds addition
Fix CIDR prefix calculation on Linux BIPv4.
Convert BSD BIPv4 to BVLCv4
Fix CMake build for BIPv4 (Linux, BSD, Windows)
Added [U]nsigned to 0xBAC0 constants
Cleanup POSIX and Win32 API sockets
Remove unnecessary file scope variable initialization
Fix routed NPDU to depend on datalink; fix warning
Remove OS dependent network code from gateway
Enable BBMD client in library by default
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
Co-authored-by: Steve Karg <steve.karg@legrand.us>
This commit is contained in:
Steve Karg
2020-04-04 11:31:54 -05:00
committed by GitHub
parent 0ce6368b43
commit eedfa58a55
51 changed files with 7178 additions and 2978 deletions
File diff suppressed because it is too large Load Diff
+122
View File
@@ -0,0 +1,122 @@
/**
* @file
* @author Steve Karg
* @date February 2020
* @brief Header file for a basic BBMD for BVLC IPv4 handler
*
* @section LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef BVLC_HANDLER_H
#define BVLC_HANDLER_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include "bacnet/bacnet_stack_exports.h"
#include "bacnet/bacdef.h"
#include "bacnet/datalink/bvlc.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* user application function prototypes */
BACNET_STACK_EXPORT
int bvlc_handler(BACNET_IP_ADDRESS *addr,
BACNET_ADDRESS *src,
uint8_t *npdu,
uint16_t npdu_len);
BACNET_STACK_EXPORT
int bvlc_send_pdu(BACNET_ADDRESS *dest,
BACNET_NPDU_DATA *npdu_data,
uint8_t *pdu,
unsigned pdu_len);
BACNET_STACK_EXPORT
uint16_t bvlc_get_last_result(void);
BACNET_STACK_EXPORT
uint8_t bvlc_get_function_code(void);
BACNET_STACK_EXPORT
void bvlc_maintenance_timer(uint16_t seconds);
BACNET_STACK_EXPORT
void bvlc_init(void);
BACNET_STACK_EXPORT
void bvlc_debug_enable(void);
/* send a Read BDT request */
BACNET_STACK_EXPORT
int bvlc_bbmd_read_bdt(BACNET_IP_ADDRESS *bbmd_addr);
/* send a Read FDT request */
BACNET_STACK_EXPORT
int bvlc_bbmd_read_fdt(BACNET_IP_ADDRESS *bbmd_addr);
/* registers with a bbmd as a foreign device */
BACNET_STACK_EXPORT
int bvlc_register_with_bbmd(
BACNET_IP_ADDRESS *address, uint16_t time_to_live_seconds);
/* Local interface to manage BBMD.
* The interface user needs to handle mutual exclusion if needed i.e.
* BACnet packet is not being handled when the BBMD table is modified.
*/
/* Get broadcast distribution table list */
BACNET_STACK_EXPORT
BACNET_IP_BROADCAST_DISTRIBUTION_TABLE_ENTRY *bvlc_bdt_list(void);
/* Invalidate all entries in the broadcast distribution table */
BACNET_STACK_EXPORT
void bvlc_bdt_list_clear(void);
/* Backup broadcast distribution table to a file.
* Filename is the BBMD_BACKUP_FILE constant
*/
BACNET_STACK_EXPORT
void bvlc_bdt_backup_local(void);
/* Restore broadcast distribution from a file.
* Filename is the BBMD_BACKUP_FILE constant
*/
BACNET_STACK_EXPORT
void bvlc_bdt_restore_local(void);
/* Set global IP address of a NAT enabled router which is used in forwarded
* messages. Enables NAT handling.
*/
BACNET_STACK_EXPORT
void bvlc_set_global_address_for_nat(const BACNET_IP_ADDRESS *addr);
/* Disable NAT handling of BBMD.
*/
BACNET_STACK_EXPORT
void bvlc_disable_nat(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+47
View File
@@ -0,0 +1,47 @@
#Makefile to build test case
CC = gcc
SRC_DIR = ../../../../src
TEST_DIR = ../../../../test
INCLUDES = -I$(SRC_DIR) -I$(TEST_DIR)
DEFINES = -DBIG_ENDIAN=0 -DBACDL_BIP -DBBMD_ENABLED=1 -DTEST -DTEST_BBMD_HANDLER
CFLAGS = -Wall $(INCLUDES) $(DEFINES) -g
SRCS = $(SRC_DIR)/bacnet/basic/bbmd/h_bbmd.c \
$(SRC_DIR)/bacnet/bacdcode.c \
$(SRC_DIR)/bacnet/bacint.c \
$(SRC_DIR)/bacnet/bacstr.c \
$(SRC_DIR)/bacnet/bacreal.c \
$(SRC_DIR)/bacnet/datalink/bvlc.c \
$(SRC_DIR)/bacnet/basic/sys/debug.c \
$(TEST_DIR)/ctest.c
TARGET_NAME = bbmd
ifeq ($(OS),Windows_NT)
TARGET_EXT = .exe
else
TARGET_EXT =
endif
TARGET = $(TARGET_NAME)$(TARGET_EXT)
all: ${TARGET}
OBJS = ${SRCS:.c=.o}
${TARGET}: ${OBJS}
${CC} -o $@ ${OBJS}
.c.o:
${CC} -c ${CFLAGS} $*.c -o $@
depend:
rm -f .depend
${CC} -MM ${CFLAGS} *.c >> .depend
clean:
rm -rf core ${TARGET} $(OBJS) *.bak *.1 *.ini
test: ${TARGET}
./${TARGET}
include: .depend