def _set_tcp_flags(self, rule): """ Sets the flags inside given flow """ l4_options = rule.get(Tokens.l4_options, {}) if Tokens.flags in l4_options: flags = l4_options[Tokens.flags] tcp_flags = TCPControlBits(flags).to_int() if self.version in ["BERYLLIUM"]: self.flows["flow"][0]["match"]["tcp-flag-match"] = { "tcp-flag": tcp_flags, } elif self.version in ["BORON", "CARBON", "NITROGEN"]: self.flows["flow"][0]["match"]["tcp-flags-match"] = { "tcp-flags": tcp_flags, }
def test_should_return_the_correct_string(self): """ Should return the correct String from tcp flags """ tcp_flags = TCPControlBits(['SYN', 'ACK']) assert_equal(tcp_flags.to_str(), '00010010')
def test_should_return_the_correct_binary(self): """ Should return the correct Binary from tcp flags """ tcp_flags = TCPControlBits(['SYN', 'ACK']) assert_equal(tcp_flags.to_bin(), '0b10010')
def test_should_return_the_correct_hexadecimal(self): """ Should return the correct Hexadecimal from tcp flags """ tcp_flags = TCPControlBits(['SYN', 'ACK']) assert_equal(tcp_flags.to_hex(), '0x12')
def test_should_return_a_hexadecimal(self): """ Should return a hex from the informed tcp flags """ tcp_flags = TCPControlBits(['SYN', 'ACK']) assert_is_instance(tcp_flags.to_hex(), str)
def test_should_return_a_binary(self): """ Should return a bin from the informed tcp flags """ tcp_flags = TCPControlBits(['SYN', 'ACK']) assert_is_instance(tcp_flags.to_bin(), str)
def test_should_return_a_integer(self): """ Should return an int from the informed tcp flags """ tcp_flags = TCPControlBits(['SYN', 'ACK']) assert_is_instance(tcp_flags.to_int(), int)
def test_should_build_a_simple_tcp_flags_with_ack_bit_enabled(self): """ Should build a simple tcp flags with ACK bit enabled """ tcp_flags = TCPControlBits(['ACK']) assert_equal(tcp_flags.control_bits['ACK'], 1)
def test_should_return_the_correct_integer(self): """ Should return the correct Integer from tcp flags """ tcp_flags = TCPControlBits(['SYN', 'ACK']) assert_equal(tcp_flags.to_int(), 18)
def test_should_have_all_bits_zeroed_because_there_is_no_valid_flag(self): """ Should have all bits zeroed because there is no valid flag """ tcp_flags = TCPControlBits(['AAA', 'BBB', 'CCC']) assert_false(any(tcp_flags.control_bits.values()))