Exemplo n.º 1
0
    def test_IP_positive(self):
        ip4_str = "1.2.3.4"
        ip4_tuple = (0x1, 0x2, 0x3, 0x4)
        self.assertEqual(Convert.ipaddr_to_tuple_of_bytes(ip4_str), ip4_tuple)

        ip6_str = '1111::2222'
        ip6_tuple = (0x11, 0x11, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
                     0x0, 0x0, 0x0, 0x22, 0x22)
        self.assertEqual(Convert.ipaddr_to_tuple_of_bytes(ip6_str), ip6_tuple)

        ip6_str = '::'
        ip6_tuple = (0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
                     0x0, 0x0, 0x0, 0x0, 0x0)
        self.assertEqual(Convert.ipaddr_to_tuple_of_bytes(ip6_str), ip6_tuple)
Exemplo n.º 2
0
 def _from_gpb_value(self, value):
     """Translates value from GPB's representation into the internal
     representation suitable for encoding."""
     if self.format.format_str == DataDescription.MAC_FMT:
         return Convert.mac_to_tuple_of_bytes(value)
     elif self.format.format_str == DataDescription.IP_FMT:
         return Convert.ipaddr_to_tuple_of_bytes(value)
     elif isinstance(value, unicode):
         return str(value)
     return value
Exemplo n.º 3
0
    def test_IP_negative(self):

        self.assertIsNone(Convert.ipaddr_to_tuple_of_bytes(1))
        self.assertIsNone(Convert.ipaddr_to_tuple_of_bytes("1.2.3.4.5"))
        self.assertIsNone(Convert.ipaddr_to_tuple_of_bytes(""))
        self.assertIsNone(Convert.ipaddr_to_tuple_of_bytes("1.2.3..4"))
        self.assertIsNone(Convert.ipaddr_to_tuple_of_bytes("1.2.256.4"))
        self.assertIsNone(Convert.ipaddr_to_tuple_of_bytes(":::"))
Exemplo n.º 4
0
 def _is_valid(self, value, name):
     try:
         fmt = self.rcptlv.child_dict_by_name[name]
         if fmt.value_is_mac():
             value = Convert.mac_to_tuple_of_bytes(value)
         elif fmt.value_is_ip_addr():
             value = Convert.ipaddr_to_tuple_of_bytes(value)
         fmt.validate(value)
         return True
     except GCPInvalidDataValueError:
         return False
     except ValueError:
         return False
     except TypeError:
         return False
Exemplo n.º 5
0
    def test_02_basic_redirect(self):
        self.logger.info("Starting ServiceSuite VMs")
        serv1 = self.topology.create_vm_service_suite("ServiceSuite1", False)
        serv2 = self.topology.create_vm_service_suite("ServiceSuite2", False)
        self.topology.start_and_wait_for_all()

        # Configure ServiceSuite1
        self.logger.info("Configuring ServiceSuite1 VM")
        msg = serv1.prepare_config_message(dhcpv4=True, dhcpv6=True, tps=True,
                                           ccapv6=True)
        msg.ServiceConfigureMessage.CcapCoreV6.IPv6Address = \
            serv1.ipv6_addresses[1]
        self.logger.debug("Setting CCAP IPv6: %s", serv1.ipv6_addresses[1])
        scenario = msg.ServiceConfigureMessage.CcapCoreV6.ClientScenarios.add()
        scenario.ScenarioType = scenario.SCENARIO_REDIRECT
        scenario.redirect_ip_addr = serv2.ipv6_addresses[1]

        reply = serv1.vm_command(msg)
        self.logger.debug("Received reply to service configuration:")
        self.logger.debug("%s", reply)
        self.assertIsNotNone(reply, "Not any reply message received from RPD")
        self.assertEqual(reply.MessageResult,
                         reply.IT_API_SERVICE_SUITE_RESULT_OK,
                         "Unexpected configuration result: {}".format(
                             reply.MessageResult))

        # Configure ServiceSuite 2
        self.logger.info("Configuring ServiceSuite2 VM")
        msg = serv2.prepare_config_message(dhcpv4=False, dhcpv6=False,
                                           tps=False, ccapv6=True)
        msg.ServiceConfigureMessage.CcapCoreV6.IPv6Address = \
            serv2.ipv6_addresses[1]
        self.logger.debug("Setting CCAP IPv6: %s", serv2.ipv6_addresses[1])
        reply = serv2.vm_command(msg)
        self.logger.debug("Received reply to service configuration:")
        self.logger.debug("%s", reply)
        self.assertIsNotNone(reply, "Not any reply message received from RPD")
        self.assertEqual(reply.MessageResult,
                         reply.IT_API_SERVICE_SUITE_RESULT_OK,
                         "Unexpected configuration result: {}".format(
                             reply.MessageResult))

        self.logger.info("Starting RPD VM")
        rpd1 = self.topology.create_vm_open_rpd("RPD1")

        self.poll_result(self.check_session, [rpd1], 30,
                         "Ccap core capabilities not set")

        msg = t_ItApiRpdMessage()
        msg.ItApiRpdMessageType = msg.IT_API_RPD_GET
        ret = rpd1.vm_command(msg)
        self.logger.info("Received DatabaseContent:")
        self.logger.info("%s", ret)
        self.assertIsNotNone(reply, "Not any reply message received from RPD")

        expected_ccap_ip = Convert.ipaddr_to_tuple_of_bytes(
            serv2.ipv6_addresses[1])
        expected_ccap_ip = Convert.bytes_to_ipv6_str(expected_ccap_ip)
        received_ccap_ip = \
            ret.DatabaseContent.cfg.CcapCoreIdentification[0].CoreIpAddress
        self.logger.info("Comparing CCAP IPs: received: %s, expected: %s",
                         received_ccap_ip, expected_ccap_ip)
        self.assertEqual(expected_ccap_ip,
                         received_ccap_ip,
                         "Invalid CcapCore IP address: {}, "
                         "expected: {}".format(received_ccap_ip,
                                               expected_ccap_ip))
Exemplo n.º 6
0
    def test_msg_dispatch_I08(self):
        print("##################test_msg_dispatch_I08##################")
        try:
            self.process.send_ipc_msg('error')
        except SystemExit as e:
            self.assertEqual(e.code, EX_DATAERR)

        self.process.send_ipc_msg({
            "session": self.session,
            "req_packet": None,
            "req_data": "error"
        })

        timeout_msg = t_RcpMessage()
        timeout_msg.RcpMessageType = timeout_msg.CONNECT_CLOSE_NOTIFICATION
        self.process.send_ipc_msg({
            "session": self.session,
            "req_packet": None,
            "req_data": timeout_msg
        })

        data_list = []
        seq = RCPSequence(gcp_msg_def.DataStructREQ,
                          rcp_tlv_def.RCP_MSG_TYPE_REX,
                          0,
                          rcp_tlv_def.RCP_OPERATION_TYPE_WRITE,
                          unittest=True)
        sub_tlv = seq.CcapCoreIdentification.add_new_repeated()
        sub_tlv.Index.set_val(1)
        sub_tlv.CoreId.set_val('1234567890')
        sub_tlv.CoreIpAddress.set_val(
            Convert.ipaddr_to_tuple_of_bytes("127.0.0.1"))
        sub_tlv.IsPrincipal.set_val(False)
        sub_tlv.CoreMode.set_val(1)
        sub_tlv.InitialConfigurationComplete.set_val(True)
        sub_tlv.MoveToOperational.set_val(True)
        sub_tlv.CoreFunction.set_val(1)
        sub_tlv.ResourceSetIndex.set_val(2)
        data_list.append(seq)

        seq = RCPSequence(gcp_msg_def.DataStructREQ,
                          rcp_tlv_def.RCP_MSG_TYPE_REX,
                          0,
                          rcp_tlv_def.RCP_OPERATION_TYPE_ALLOCATE_WRITE,
                          unittest=True)
        sub_tlv = seq.RfPort.add_new_repeated()
        sub_tlv.RfPortSelector.RfPortIndex.set_val(0)
        sub_tlv.DsRfPort.AdminState.set_val(1)
        sub_tlv.DsRfPort.BasePower.set_val(30)
        sub_tlv.DsRfPort.RfMute.set_val(0)
        sub_tlv.DsRfPort.TiltSlope.set_val(8)
        sub_tlv.DsRfPort.TiltMaximumFrequency.set_val(15)
        data_list.append(seq)

        seq = RCPSequence(gcp_msg_def.DataStructREQ,
                          rcp_tlv_def.RCP_MSG_TYPE_REX,
                          0,
                          rcp_tlv_def.RCP_OPERATION_TYPE_ALLOCATE_WRITE,
                          unittest=True)
        seq.RpdConfigurationDone.set_val(1)
        data_list.append(seq)

        seq = RCPSequence(gcp_msg_def.DataStructREQ,
                          rcp_tlv_def.RCP_MSG_TYPE_REX, 0,
                          rcp_tlv_def.RCP_OPERATION_TYPE_ALLOCATE_WRITE)
        seq.ipc_msg = None
        data_list.append(seq)

        self.process.hal_ipc.disconnected = False
        self.process.hal_ipc.clientID = '12345'
        self.process.send_ipc_msg({
            "session": self.session,
            "req_packet": 'tmp',
            "gcp_msg": "tmp",
            "req_data": data_list
        })
Exemplo n.º 7
0
 def _expand_ip_addr(addr):
     # 'fd00:dead:0001:0000:0000:0000:0000:0009'
     expanded = Convert.bytes_to_ipv6_str(
         Convert.ipaddr_to_tuple_of_bytes(addr)).lower()
     # 'fd00::1' -> 'fd:00:00:00:...:00:00:00:09'
     return ':'.join(x[:2] + ':' + x[2:] for x in expanded.split(':'))