diff --git a/devices/CMakeLists.txt b/devices/CMakeLists.txt index b725fee428a025c3b3ef8bcefcaa433c11c89f91..894b617385550ca6e8ec7e139674691a837318f5 100644 --- a/devices/CMakeLists.txt +++ b/devices/CMakeLists.txt @@ -8,3 +8,4 @@ add_subdirectory(dlink-cam) add_subdirectory(philips-hue) add_subdirectory(smartthings-hub) add_subdirectory(amazon-echo) +add_subdirectory(example) \ No newline at end of file diff --git a/devices/example/profile.yaml b/devices/example/profile.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f2da6bbddd210a98dc00ada26cf3042d9aac7f85 --- /dev/null +++ b/devices/example/profile.yaml @@ -0,0 +1,105 @@ +--- +device-info: + name: example + mac: b0:c5:54:43:54:83 + ipv4: 192.168.1.115 + ipv6: fddd:ed18:f05b:0:d8a3:adc0:f68f:e5cf + mud-version: 1 + mud-url: https://smartthings-hub.com/smartthings-hub + last-update: "2022-03-15T10:27:29.170+01:00" + cache-validity: 100 + is-supported: true + + +patterns: + + dns-ipv4: + protocols: + dns: + qtype: A + domain-name: # Will be populated by parsing # + udp: + dst-port: 53 + ipv4: + src: self + dst: gateway + bidirectional: true + +single-policies: + + # DNS over IPv4 + dns-ipv4: + protocols: + dns: + qtype: + - A + - AAAA + domain-name: + - connectivity.smartthings.com + - api.smartthings.com + - fw-update2.smartthings.com + udp: + dst-port: 53 + ipv4: + src: self + dst: gateway + bidirectional: true + + +interactions: + + # Retrieve IPv4 address with DHCP + get-ip-address: + + dhcp-discover: + protocols: + dhcp: + type: discover + client-mac: self + udp: + src-port: 68 + dst-port: 67 + ipv4: + src: 0.0.0.0 + dst: broadcast + timeout: 1 + + dhcp-offer: + protocols: + dhcp: + type: offer + client-mac: self + udp: + src-port: 67 + dst-port: 68 + ipv4: + src: gateway + dst: self + timeout: 2 + + dhcp-request: + protocols: + dhcp: + type: request + client-mac: self + udp: + src-port: 68 + dst-port: 67 + ipv4: + src: 0.0.0.0 + dst: broadcast + timeout: 3 + + dhcp-ack: + protocols: + dhcp: + type: ack + client-mac: self + udp: + src-port: 67 + dst-port: 68 + ipv4: + src: gateway + dst: self + timeout: 4 + \ No newline at end of file diff --git a/eval/fuzzing/load-configuration.sh b/eval/fuzzing/load-configuration.sh new file mode 100755 index 0000000000000000000000000000000000000000..449da47e36624e071c321703f8e90b5b59cfaeff --- /dev/null +++ b/eval/fuzzing/load-configuration.sh @@ -0,0 +1,7 @@ +echo "Input device: $1" +sudo nft flush ruleset +echo "Flushing ruleset" +sudo nft -f ~/iot-firewall/devices/$1/firewall.nft +echo "Loading ruleset" +echo "Running NFQueue for $1" +sudo ~/iot-firewall/bin/$1 diff --git a/eval/latency/dlink-cam/flow.yml b/eval/latency/dlink-cam/flow.yml new file mode 100644 index 0000000000000000000000000000000000000000..1a50a478804b24de59c42fa7d06c31b266ddbdb4 --- /dev/null +++ b/eval/latency/dlink-cam/flow.yml @@ -0,0 +1,21 @@ +appId: com.dlink.mydlinkunified +name: D-Link Caméra +--- +- launchApp: + appId: "com.dlink.mydlinkunified" + # clearState: true + stopApp: true + label: Start the D-Link app +- tapOn: + id: "com.dlink.mydlinkunified:id/clStatus" + label: "Open the camera" +- waitForAnimationToEnd: + timeout: 10000 + label: "Wait 10 secs" +- launchApp: + appId: "com.amazon.dee.app" + label: "Open the Amazon Alexa app" + # clearState: true + stopApp: true +- tapOn: "Cameras" +- tapOn: "Camera D" diff --git a/eval/latency/philips-hue/alexa.yml b/eval/latency/philips-hue/alexa.yml new file mode 100644 index 0000000000000000000000000000000000000000..2a5246df3ccc614c839e5c4c9c3450b22710ff2e --- /dev/null +++ b/eval/latency/philips-hue/alexa.yml @@ -0,0 +1,43 @@ +appId: com.amazon.dee.app +name: "Power-on/off TP-Link plug using Alexa" +--- +- launchApp: + clearState: false + stopApp: true + label: "Open the Amazon Alexa app" +- tapOn: + id: "com.amazon.dee.app:id/tab_channels_device" + label: "Open the Devices tab" +- tapOn: + id: "DevicePageSearchButton" + label: "Open the search menu" +- tapOn: + id: "DeviceSearchPageSearchInput_SearchInput" + label: "Open the search bar" +- inputText: + text: "Lamp" + label: "Type 'Lamp' in the search bar" +- doubleTapOn: + text: "Lamp" + index: 1 + label: "Select the Philips Hue lamp" +- tapOn: + point: "50%,23%" + label: "Turn on the lamp" +- tapOn: + id: "ColorControl::Color=Custom-primary" + label: "Open the color picker" +- scroll: + label: "Scroll down the color picker" +- tapOn: + text: "Orange" + label: "Set the color to orange" +- tapOn: + id: "header-back-button" + label: "Close the color picker" +- tapOn: + point: "85%,55%" + label: "Set the power to 100%" +- tapOn: + point: "50%,23%" + label: "Turn off the lamp" diff --git a/eval/latency/philips-hue/flow.yml b/eval/latency/philips-hue/flow.yml new file mode 100644 index 0000000000000000000000000000000000000000..edcabe003f1be5ffd804f034b820337edebfe917 --- /dev/null +++ b/eval/latency/philips-hue/flow.yml @@ -0,0 +1,30 @@ +appId: com.tplink.kasa_android +--- +- runFlow: + file: hue.yml + label: "Edit the light using Hue" +- runFlow: + file: hueEssentials.yml + label: "Edit the light using Hue Essentials" +- runFlow: + file: alexa.yml + label: "Edit the light using Alexa" +- runFlow: + file: wifi.yml + label: "Switch Wi-Fi to UCLouvain" + env: + WIFI: UCLouvain +- runFlow: + file: hue.yml + label: "Edit the light using Hue" +- runFlow: + file: hueEssentials.yml + label: "Edit the light using Hue Essentials" +- runFlow: + file: alexa.yml + label: "Edit the light using Alexa" +- runFlow: + file: wifi.yml + label: "Switch Wi-Fi to OpenWrt-5GHz" + env: + WIFI: OpenWrt-5GHz diff --git a/eval/latency/philips-hue/hue.yml b/eval/latency/philips-hue/hue.yml new file mode 100644 index 0000000000000000000000000000000000000000..9aa1e94c7d8e4fac70f66d867cca13cddb6048ad --- /dev/null +++ b/eval/latency/philips-hue/hue.yml @@ -0,0 +1,29 @@ +appId: com.philips.lighting.hue2 +name: Hue +--- +- launchApp: + appId: "com.philips.lighting.hue2" + clearState: false + stopApp: true + label: "Open the Hue app" +- tapOn: + text: "Office" + label: "Turn on the light" +- tapOn: + point: "50%,31%" + label: "Select the room" +- tapOn: + point: "19%,64%" + label: "Select the light" +- tapOn: "Effects" +- "scroll" +- tapOn: + point: "39%,49%" + label: "Switch color to `Opal`" +- "back" +- tapOn: + point: "15%,14%" + label: "Change the brightness" +- tapOn: + point: "19%,71%" + label: "Turn off the light" diff --git a/eval/latency/philips-hue/hueEssentials.yml b/eval/latency/philips-hue/hueEssentials.yml new file mode 100644 index 0000000000000000000000000000000000000000..2f850c0542e1f5331f6955f46801d14062593d8a --- /dev/null +++ b/eval/latency/philips-hue/hueEssentials.yml @@ -0,0 +1,41 @@ +appId: com.superthomaslab.hueessentials +name: Hue Essentials +--- +- launchApp: + appId: "com.superthomaslab.hueessentials" + clearState: false + stopApp: true + label: "Open the Hue Essentials app" +- tapOn: + text: "Office" + index: 1 + label: "Tap on the Office room" +- tapOn: + point: "87%,31%" + label: "Turn on the light" +- tapOn: + point: "81%,76%" + label: "Open the device settings" +- tapOn: + point: "61%,76%" + label: "Open the color picker" +- eraseText: + label: "Remove the old HEX color" +- inputText: + text: "#3F2A56" + label: "Set the new HEX color to purple" +- tapOn: + id: "com.google.android.inputmethod.latin:id/0_resource_name_obfuscated" + index: 82 + label: "Select the purple color" +- hideKeyboard: + label: "Hide the keyboard" +- tapOn: + point: "50%,16%" + label: "Set the power to 50%" +- tapOn: + text: "Close" + label: "Close the device settings" +- tapOn: + point: "87%,31%" + label: "Turn off the light" \ No newline at end of file diff --git a/eval/latency/philips-hue/smarthings.yml b/eval/latency/philips-hue/smarthings.yml new file mode 100644 index 0000000000000000000000000000000000000000..253e5a8235dff35db27fa7dd4a616e1bd70d7884 --- /dev/null +++ b/eval/latency/philips-hue/smarthings.yml @@ -0,0 +1,11 @@ +appId: com.samsung.android.oneconnect +title: "Power-on/off TP-Link plug using SmartThings" +--- +- launchApp: + appId: "com.samsung.android.oneconnect" + clearState: false + stopApp: true + label: "Open the SmartThings app" +- tapOn: + id: "com.samsung.android.oneconnect:id/menu_devices" + label: "Open the Devices tab" \ No newline at end of file diff --git a/eval/latency/philips-hue/wifi.yml b/eval/latency/philips-hue/wifi.yml new file mode 100644 index 0000000000000000000000000000000000000000..5b6a2e7ac08ed235e4d8a51be181717f49ce2b1f --- /dev/null +++ b/eval/latency/philips-hue/wifi.yml @@ -0,0 +1,20 @@ +appId: com.android.settings +name: "Connect to a Wi-Fi network" +# env: +# WIFI : "wifiname" + +--- +- launchApp: + # appId: "com.android.settings" + clearState: false + stopApp: true + label: "Open the Settings app" +- tapOn: + text: "Network & internet" + label: "Open the Network & internet settings" +- tapOn: + text: "Wi‑Fi" + label: "Open the Wi-Fi settings" +- tapOn: + text: ${WIFI} + label: "Connect to the provided Wi-Fi network" \ No newline at end of file diff --git a/eval/latency/tplink-plug/alexa.yml b/eval/latency/tplink-plug/alexa.yml new file mode 100644 index 0000000000000000000000000000000000000000..38775afa86670cfa7f87adaa07cd7ced2ff7ae77 --- /dev/null +++ b/eval/latency/tplink-plug/alexa.yml @@ -0,0 +1,28 @@ +appId: com.amazon.dee.app +name: "Power-on/off TP-Link plug using Alexa" +--- +- launchApp: + clearState: false + stopApp: true + label: "Open the Amazon Alexa app" +- tapOn: + id: "com.amazon.dee.app:id/tab_channels_device" + label: "Open the Devices tab" +- tapOn: + id: "DevicePageSearchButton" + label: "Open the search menu" +- tapOn: + id: "DeviceSearchPageSearchInput_SearchInput" + label: "Open the search bar" +- inputText: + text: "TP-Link" + label: "Type 'TP-Link' in the search bar" +- doubleTapOn: + text: "TP-Link plug" + label: "Select the TP-Link plug" +- tapOn: + point: "50%,23%" + label: "Toggle the plug power" +- tapOn: + point: "50%,23%" + label: "Toggle the plug power" diff --git a/eval/latency/tplink-plug/flow.yml b/eval/latency/tplink-plug/flow.yml new file mode 100644 index 0000000000000000000000000000000000000000..0d7cb5e9bacc59088c55cd75174ef574f2512503 --- /dev/null +++ b/eval/latency/tplink-plug/flow.yml @@ -0,0 +1,30 @@ +appId: com.tplink.kasa_android +--- +- runFlow: + file: kasa.yml + label: "Power-on/off TP-Link plug using Kasa" +- runFlow: + file: smarthings.yml + label: "Power-on/off TP-Link plug using SmartThings" +- runFlow: + file: "alexa.yml" + label: "Power-on/off TP-Link plug using Alexa" +- runFlow: + file: "wifi.yml" + env: + WIFI: "UCLouvain" + label: "Connect to the UCLouvain Wi-Fi network" +- runFlow: + file: kasa.yml + label: "Power-on/off TP-Link plug using Kasa" +- runFlow: + file: smarthings.yml + label: "Power-on/off TP-Link plug using SmartThings" +- runFlow: + file: "alexa.yml" + label: "Power-on/off TP-Link plug using Alexa" +- runFlow: + file: "wifi.yml" + env: + WIFI: "OpenWrt-5GHz" + label: "Connect to the OpenWrt-5GHz Wi-Fi network" \ No newline at end of file diff --git a/eval/latency/tplink-plug/kasa.yml b/eval/latency/tplink-plug/kasa.yml new file mode 100644 index 0000000000000000000000000000000000000000..c2e22e55775ba230e17cef08fc88fa40dfcfef63 --- /dev/null +++ b/eval/latency/tplink-plug/kasa.yml @@ -0,0 +1,14 @@ +appId: com.tplink.kasa_android +title: "Power-on/off TP-Link plug using Kasa" +--- +- launchApp: + appId: "com.tplink.kasa_android" + clearState: false + stopApp: true + label: "Open the Kasa app" +- tapOn: + id: "com.tplink.kasa_android:id/device_switch" + label: "Toggle the plug power" +- tapOn: + id: "com.tplink.kasa_android:id/device_switch" + label: "Toggle the plug power" \ No newline at end of file diff --git a/eval/latency/tplink-plug/smarthings.yml b/eval/latency/tplink-plug/smarthings.yml new file mode 100644 index 0000000000000000000000000000000000000000..253e5a8235dff35db27fa7dd4a616e1bd70d7884 --- /dev/null +++ b/eval/latency/tplink-plug/smarthings.yml @@ -0,0 +1,11 @@ +appId: com.samsung.android.oneconnect +title: "Power-on/off TP-Link plug using SmartThings" +--- +- launchApp: + appId: "com.samsung.android.oneconnect" + clearState: false + stopApp: true + label: "Open the SmartThings app" +- tapOn: + id: "com.samsung.android.oneconnect:id/menu_devices" + label: "Open the Devices tab" \ No newline at end of file diff --git a/eval/latency/tplink-plug/wifi.yml b/eval/latency/tplink-plug/wifi.yml new file mode 100644 index 0000000000000000000000000000000000000000..5b6a2e7ac08ed235e4d8a51be181717f49ce2b1f --- /dev/null +++ b/eval/latency/tplink-plug/wifi.yml @@ -0,0 +1,20 @@ +appId: com.android.settings +name: "Connect to a Wi-Fi network" +# env: +# WIFI : "wifiname" + +--- +- launchApp: + # appId: "com.android.settings" + clearState: false + stopApp: true + label: "Open the Settings app" +- tapOn: + text: "Network & internet" + label: "Open the Network & internet settings" +- tapOn: + text: "Wi‑Fi" + label: "Open the Wi-Fi settings" +- tapOn: + text: ${WIFI} + label: "Connect to the provided Wi-Fi network" \ No newline at end of file diff --git a/include/nfqueue.h b/include/nfqueue.h index b43a4f7a489d7fff4ac0f2f9da7b4f5e0d080a3a..7d1bfdcafbebec40ef929002c47e601ae1472aa0 100644 --- a/include/nfqueue.h +++ b/include/nfqueue.h @@ -12,6 +12,7 @@ #include <stdio.h> #include <stdlib.h> +#include <time.h> #include <unistd.h> #include <sys/time.h> #include <netinet/in.h> @@ -23,6 +24,7 @@ #include "rule_utils.h" #include "packet_utils.h" +#define DEFAULT_TIMEOUT 3600 // Default timeout is one sec /** * @brief Structure which stores the data relative to one policy interaction. @@ -35,6 +37,8 @@ typedef struct { uint8_t current_state; // Current state counters_t *counters; // Array of counters ip_addr_t cached_ip; // Cached IP address + double timeout; // Timeout of the request (in sec). 0 = DEFAULT_TIMEOUT ; -1 = no timeout + time_t time_request; // Time since last request ; set to 0 if no request has been made before } interaction_data_t; /** @@ -116,5 +120,15 @@ void bind_queue(uint16_t queue_num, basic_callback *callback, void *arg); */ void* nfqueue_thread(void *arg); +/** + * @brief Check if the last request is too old to be accepted + * + * @param threshold time in sec before dropping the request + * @param last_request time of the last request + * @return true the request is too old and must be refused + * @return false the request is recent enought and might be accepted + */ +bool is_timedout(double threshold, time_t last_request); + #endif /* _IOTFIREWALL_NFQUEUE_ */ diff --git a/src/nfqueue.c b/src/nfqueue.c index 4ebe6c238aadf41980d5a4463f56655e3a927980..6c20bd255e18dbbda4b8fc71684de78cd99cb6b1 100644 --- a/src/nfqueue.c +++ b/src/nfqueue.c @@ -211,3 +211,39 @@ void* nfqueue_thread(void *arg) { bind_queue(thread_arg->queue_id, thread_arg->func, thread_arg->arg); return NULL; } + +/** + * @brief Check if the last request is too old to be accepted + * + * @param threshold time in sec before dropping the request + * @param last_request time of the last request + * @return true the request is too old and must be refused + * @return false the request is recent enought and might be accepted + */ +bool is_timedout(double threshold, time_t last_request) { + // first request or timeout is disabled + if (last_request == 0 || threshold == -1) { + #ifdef DEBUG + puts("\nFirst request or no timeout has been given") ; + #endif + return false ; // laugh in C and accept the request + } + + if (threshold == 0) { // If there is no timeout, use the default one + threshold = DEFAULT_TIMEOUT ; + #ifdef DEBUG + printf("\nNo timeout given, defaulting to %d", DEFAULT_TIMEOUT) ; + #endif + } // default is define in nfqueue.h + + time_t now = time(NULL); // get the time NOW + + double diff = difftime(now, last_request) ; + + #ifdef DEBUG + printf("\nComparing the last request %ld and the time now %ld : %f", last_request, now, diff) ; + printf("\nthreshold (%f) < diff = %b", threshold,(threshold < diff)) ; + #endif + + return threshold < diff ; +} diff --git a/src/translator/NFQueue.py b/src/translator/NFQueue.py index 2c53464307c8894c8a1bb063976191e5eb411ad9..f58041284b911386e209a6e18fa2e0a01771606f 100644 --- a/src/translator/NFQueue.py +++ b/src/translator/NFQueue.py @@ -197,10 +197,11 @@ class NFQueue: :param policy_idx: index of the policy inside the interaction :param state: state for which the policy must be added :param policy: policy to add + :param timeout: the timeout of the policy :return: True if the nfqueue queue number has been updated, False otherwise """ result = False - + timeout = policy.timeout # Update nfqueue queue number if necessary if self.queue_num < 0 and policy.queue_num >= 0: self.queue_num = policy.queue_num @@ -212,7 +213,8 @@ class NFQueue: "policy_idx": policy_idx, "state": state, "policy": policy, - "counters_idx": {} + "counters_idx": {}, + "timeout": timeout } # Update NFT stat matches if necessary diff --git a/src/translator/Policy.py b/src/translator/Policy.py index 1c5cb31e26fc65484b4d20232396a15e7575789f..1df1cc760d0f6442887b3fde4165c79334ee0940 100644 --- a/src/translator/Policy.py +++ b/src/translator/Policy.py @@ -30,7 +30,7 @@ class Policy: "duration": {"counter": True} } - def __init__(self, interaction_name: str, policy_name: str, profile_data: dict, device: dict, is_backward: bool = False, in_interaction: bool = False) -> None: + def __init__(self, interaction_name: str, policy_name: str, profile_data: dict, device: dict, is_backward: bool = False, in_interaction: bool = False, timeout = 0) -> None: """ Initialize a new Policy object. @@ -57,6 +57,7 @@ class Policy: self.counters = {} # Counters associated to this policy (will be populated by parsing) self.is_device = False # Whether the policy involves the device self.other_host = {} # If the policy does not involve the device, this will be set to the IP address of the other local involved device + self.timeout = timeout self.is_bidirectional = self.profile_data.get("bidirectional", False) # Whether the policy is bidirectional self.transient = self.is_transient() # Whether the policy represents a transient pattern diff --git a/src/translator/templates/callback.c.j2 b/src/translator/templates/callback.c.j2 index 8f9bd91bcdb4e39bbe79d8bb3229aee544d36e52..274f95c998bfb6185f624ebedfa9727eb07e97a8 100644 --- a/src/translator/templates/callback.c.j2 +++ b/src/translator/templates/callback.c.j2 @@ -20,6 +20,10 @@ #endif /* DEBUG */ verdict = NF_STOP; + {% if interaction_data %} + {{interaction_data}}.time_request = time(NULL) ; + {% endif%} + {% endmacro %} {% macro write_callback_function(loop_index, nfqueue) %} @@ -186,14 +190,28 @@ uint32_t callback_{{nfqueue_name}}(int pkt_id, int pkt_len, uint8_t *payload, vo {% set duration = "(interactions_data[{}].counters + {})->duration".format(interaction_idx, counters_idx["duration"]) %} {% endif %} {% endif %} - + {% if state >= 0 %} + {% set timeout = policy["timeout"]%} {% set policy_name = "{}#{}".format(policy.interaction_name, policy.name) %} // Policy {{policy_name}} pthread_mutex_lock(&({{interaction_data}}.mutex)); #if defined DEBUG || defined LOG previous_state = {{interaction_data}}.current_state; #endif + + if (is_timedout({{timeout}}, {{interaction_data}}.time_request) && ({{interaction_data}}.current_state != 0)) { + {{interaction_data}}.current_state = 0 ; // reset the interaction + {{interaction_data}}.time_request = time(NULL) ; + + #if defined DEBUG + puts("Packet is too old, dropped. current_state has been reset") ; + #endif + pthread_mutex_unlock(&({{interaction_data}}.mutex)); + + return NF_DROP; + } + if ( {% if "packet-count" in counters_idx %} {{packet_count}}.is_initialized && @@ -205,19 +223,19 @@ uint32_t callback_{{nfqueue_name}}(int pkt_id, int pkt_len, uint8_t *payload, vo ( {% if ( policy.transient and ( not policy.is_backward and (previous_policy.transient or previous_policy.periodic) ) ) or ( (policy.transient or policy.periodic) and policy.is_backward and (second_previous_policy.transient or second_previous_policy.periodic) ) %} {% set previous_state = (state - 1) % (max_state + 1) if policy.periodic else (state - 2) % (max_state + 1) %} - {{interaction_data}}.current_state == {{previous_state}} || + {{interaction_data}}.current_state >= {{previous_state}} || {% endif %} {% if previous_policy.transient or policy.transient or (policy_idx == 0 and previous_policy.periodic) %} {% set previous_state = state if policy.periodic else (state - 1) % (max_state + 1) %} - {{interaction_data}}.current_state == {{previous_state}} || + {{interaction_data}}.current_state >= {{previous_state}} || {% endif %} {% if policy.periodic and policy_idx != num_policies - 1 %} - {{interaction_data}}.current_state == {{(state + 1) % (max_state + 1)}} + {{interaction_data}}.current_state >= {{(state + 1) % (max_state + 1)}} {%- if policy.periodic and policy_idx == 0 %} || {% endif %} {% endif %} {% if (policy.periodic and policy_idx == 0) or not (policy.periodic and policy_idx != num_policies - 1) %} - {{interaction_data}}.current_state == {{state}} + {{interaction_data}}.current_state >= {{state}} {% endif %} ) {% if policy.nfq_matches %} @@ -357,7 +375,7 @@ uint32_t callback_{{nfqueue_name}}(int pkt_id, int pkt_len, uint8_t *payload, vo #ifdef DEBUG printf("{{policy_name}}: State %hhu -> State {{(state + 1) % (max_state + 1)}}\n", {{interaction_data}}.current_state); #endif - {{interaction_data}}.current_state = {{(state + 1) % (max_state + 1)}}; + if({{interaction_data}}.current_state == {{state}}) {{interaction_data}}.current_state = {{(state + 1) % (max_state + 1)}}; {% endif %} {% if policy.transient %} {% if "packet-count" in policy.counters %} @@ -384,7 +402,7 @@ uint32_t callback_{{nfqueue_name}}(int pkt_id, int pkt_len, uint8_t *payload, vo #ifdef DEBUG printf("{{policy_name}}: State %hhu -> State {{(state + 1) % (max_state + 1)}}\n", {{interaction_data}}.current_state); #endif - {{interaction_data}}.current_state = {{(state + 1) % (max_state + 1)}}; + if({{interaction_data}}.current_state == {{state}}){{interaction_data}}.current_state = {{(state + 1) % (max_state + 1)}}; {% if "packet-count" in policy.counters %} {{packet_count}}.is_initialized = false; {% endif %} diff --git a/src/translator/translator.py b/src/translator/translator.py index b78bb404206febb011d7167ea4376a9fa16a3dd1..cb3e5fd290a1be2e68d0a6edfa5c6611ce587a65 100644 --- a/src/translator/translator.py +++ b/src/translator/translator.py @@ -298,6 +298,10 @@ if __name__ == "__main__": for single_policy_name in single_policies: # Create policy and parse it profile_data = single_policies[single_policy_name] + try: + timeout = profile_data["timeout"] + except KeyError: + timeout = 0 is_backward = "backward" in single_policy_name and profile_data.get("bidirectional", False) policy_data = { "interaction_name": interaction_policy_name, @@ -305,7 +309,8 @@ if __name__ == "__main__": "profile_data": profile_data, "device": device, "is_backward": is_backward, - "in_interaction": True + "in_interaction": True, + "timeout": timeout } single_policy, new_nfq = parse_policy(policy_data, interaction_data, global_accs, len(single_policies), True, args.log_type, args.log_group) if new_nfq: