def build_cross():
    object_lst = pickle.load(open('./maps/cross00_object.p', 'rb'))
    # randomize intensity decay of objects
    for obj in object_lst:
        obj.decay = np.random.uniform()
    rect_idx_lst = pickle.load(open('./maps/cross00_rectidx.p', 'rb'))
    gate_lst = [Gateway(np.float32((10,10)), tx_power=100, ff_attenuation=1e-2),
                Gateway(np.float32((77,60)), tx_power=100, ff_attenuation=1e-2),
                Gateway(np.float32((74,7)), tx_power=100, ff_attenuation=1e-2)]
    return object_lst, rect_idx_lst, gate_lst
Ejemplo n.º 2
0
 def _parse_gateway(gateway_child: ElementTree) -> Gateway:
     id = gateway_child.get('id')
     name = gateway_child.find('Name').text
     type = gateway_child.find('Type').text.lower()
     gates = []
     distribution = None
     rule = None
     if type == GATEWAY_TYPES['choice']:
         distribution_child = gateway_child.find('Distribution')
         rule_child = gateway_child.find('Rule')
         if distribution_child is not None and len(
                 list(distribution_child)):
             distribution = []
             for gate in distribution_child:
                 gates.append(gate.get('id'))
                 distribution.append(float(gate.text))
         elif rule_child is not None and len(list(rule_child)):
             for gate in rule_child:
                 gates.append(gate.get('id'))
             rule = id
         else:
             raise ValueError(
                 "For choice gateways, either rule or distribution must be present."
             )
     elif type == GATEWAY_TYPES['parallel'] or type == GATEWAY_TYPES[
             'merge']:
         gates_child = gateway_child.find('Gates')
         for gate in gates_child:
             gates.append(gate.get('id'))
     return Gateway(id=id,
                    name=name,
                    type=type,
                    gates=gates,
                    distribution=distribution,
                    rule=rule)
Ejemplo n.º 3
0
    def update_gateway_with_prefixlen(self,
                                      ipv4='',
                                      ipv4_prefixlen=0,
                                      ipv6='',
                                      ipv6_prefixlen=0,
                                      port_no=''):
        """
            update the gateway information for Port object.
        """
        port = self.ports[port_no]

        if port.gateway is None:
            port.gateway = Gateway(name=port.name,
                                   port_no=port.port_no,
                                   ipv4=ipv4,
                                   ipv4_prefixlen=ipv4_prefixlen,
                                   ipv6=ipv6,
                                   ipv6_prefixlen=ipv6_prefixlen)
        else:
            port.gateway.name = port.name
            port.gateway.ipv4 = netaddr.IPAddress(ipv4)
            port.gateway.ipv4_subnet = netaddr.IPNetwork(ipv4 + '/' +
                                                         str(ipv4_prefixlen))
            port.gateway.ipv6 = netaddr.IPAddress(ipv6)
            port.gateway.ipv6_subnet = netaddr.IPNetwork(ipv6 + '/' +
                                                         str(ipv6_prefixlen))
            port.gateway.port_no = port.port_no

        self.tbl.update_entry(subnet=port.gateway.ipv4_subnet,
                              receive_port=port,
                              metric=0,
                              source="CONNECTED")
Ejemplo n.º 4
0
def add_gateway_by_IMEI():
    IMEI = request.args.get('IMEI')
    latest_info_file = open("./latest_info", "r")
    # 101,5001,1
    info = latest_info_file.readline().strip().split(",")
    latest_info_file.close()
    ip = str(int(info[0]) + 1)
    vpn_ip = "172.16.0." + ip
    vpn_port = str(int(info[1]) + 1)
    server_ip = "smrtyan.cn"
    server_port = vpn_port
    num = str(int(info[2]) + 1)
    culiu = "culiu" + num

    gateway = Gateway(IMEI, vpn_ip, vpn_port, server_ip, server_port, culiu)
    # "867698045127654", "172.16.0.102", 5002, "smrtyan.cn", 5002, "culiu2"
    gateway.add()

    latest_info_file = open("./latest_info", "w")
    latest_info_file.write(ip + "," + vpn_port + "," + num)
    latest_info_file.close()
    # return the ./script/client_config.py file
    try:
        return send_file('./script/client_config.py',
                         attachment_filename='client_config.py')
    except Exception as e:
        return str(e)
Ejemplo n.º 5
0
 def test_add_dhcp_host_exception(self):
     """
     Test add_dhcp_host action raises exception
     """
     with pytest.raises(
             ValueError,
             message=
             'action should raise an error if configure_dhcp raises an exception'
     ):
         self.valid_data['networks'] = [{
             'name': 'network',
             'dhcpserver': {
                 'hosts': [{
                     'macaddress': 'address1',
                     'hostname': 'one'
                 }]
             }
         }]
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw.add_dhcp_host('network', {
             'macaddress': 'address2',
             'hostname': 'one'
         })
         assert gw.data['networks'] == []
         assert gw._gateway_sal.configure_dhcp.call_count == 2
         assert gw._gateway_sal.configure_cloudinit.call_count == 2
Ejemplo n.º 6
0
def UI_init():
    global GW
    app.btn_rl1_bat.clicked.connect(ctr_R1_bat)
    app.btn_rl1_tat.clicked.connect(ctr_R1_tat)
    app.btn_rl2_bat.clicked.connect(ctr_R2_bat)
    app.btn_rl2_tat.clicked.connect(ctr_R2_tat)

    ports = serial.tools.list_ports.comports()
    check_device = ''

    if (len(ports) > 0):
        for port in ports:
            # print(port)
            if ("USB-SERIAL CH340" in str(port)):
                check_device = port.device
                break
        if (check_device != ''):
            GW = Gateway(CONSTANT.GW_NAME)
            # QMessageBox.information(
            #     app, "KẾT NỐI THÀNH CÔNG", "CHÀO MỪNG BẠN ĐẾN VỚI VƯỜN CỦA NHUNG ĐẠI KA")
            app.lbl_com.setText("ĐÃ KẾT NỐI " + check_device)
            # GW.control_RL(1, 0)
            # GW.control_RL(2, 0)
        else:
            QMessageBox.critical(app, "LỖI KẾT NỐI", "KHÔNG ĐÚNG THIẾT BỊ")
            sys.exit()
    else:
        QMessageBox.critical(app, "LỖI KẾT NỐI",
                             "KHÔNG CÓ COM NÀO ĐƯỢC KẾT NỐI")
        sys.exit()
Ejemplo n.º 7
0
 def test_remove_http_proxy_doesnt_exist(self):
     """
     Test remove_http_proxy action if proxy doesn't exist
     """
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'start', 'ok')
     gw.remove_http_proxy('proxy')
Ejemplo n.º 8
0
    def __init__(self, itf, addr_list):
        #self._exo = exo
        self._itf = itf
        self._addr_list = addr_list

        # Create gateway object
        gatewayObject = Gateway()
Ejemplo n.º 9
0
 def test_remove_network_name_exist(self):
     """
     Test remove_network action if network with name doesnt exist
     """
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'start', 'ok')
     gw.remove_network('network')
Ejemplo n.º 10
0
 def test_add_http_proxy_host_exists(self):
     """
     Test add_http_proxy action if another proxy has the same host
     """
     with pytest.raises(
             ValueError,
             message=
             'action should raise an error if another http proxy with the same host exist'
     ):
         proxy = {
             'host': 'host',
             'destinations': ['destination'],
             'types': ['http'],
             'name': 'proxy'
         }
         proxy2 = {
             'host': 'host',
             'destinations': ['destination'],
             'types': ['http'],
             'name': 'proxy2'
         }
         self.valid_data['httpproxies'].append(proxy)
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw.add_http_proxy(proxy2)
Ejemplo n.º 11
0
 def test_remove_portforward_doesnt_exist(self):
     """
     Test remove_portforward action if the portforward doesn't exist
     """
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'start', 'ok')
     gw.remove_portforward('pf')
Ejemplo n.º 12
0
 def test_add_portforward_combination_exists_different_protocols(self):
     """
     Test add_portforward action when another portforward with the same srcnetwork and srcport exists and have different protocols
     """
     portforward_one = {
         'name': 'pf2',
         'dstip': '196.23.12.42',
         'dstport': 22,
         'srcnetwork': 'network',
         'srcport': 22,
         'protocols': ['udp']
     }
     self.valid_data['portforwards'] = [portforward_one]
     self.valid_data['networks'] = [{'name': 'network'}]
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'start', 'ok')
     portforward_two = {
         'name': 'pf',
         'dstip': '196.23.12.42',
         'dstport': 22,
         'srcnetwork': 'network',
         'srcport': 22,
         'protocols': ['tcp']
     }
     gw.add_portforward(portforward_two)
     assert gw.data['portforwards'] == [portforward_one, portforward_two]
Ejemplo n.º 13
0
 def test_add_portforward_combination_exists_same_protocols(self):
     """
     Test add_portforward action when another portforward with the same srcnetwork and srcport exists and have the same protocols
     """
     with pytest.raises(
             ValueError,
             message=
             'action should raise an error if another portforward with the same name exist'
     ):
         self.valid_data['portforwards'] = [{
             'name': 'pf2',
             'dstip': '196.23.12.42',
             'dstport': 22,
             'srcnetwork': 'network',
             'srcport': 22,
             'protocols': ['tcp']
         }]
         self.valid_data['networks'] = [{'name': 'network'}]
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         portforward = {
             'name': 'pf',
             'dstip': '196.23.12.42',
             'dstport': 22,
             'srcnetwork': 'network',
             'srcport': 22,
             'protocols': ['tcp']
         }
         gw.add_portforward(portforward)
Ejemplo n.º 14
0
 def test_remove_dhcp_host_exception(self):
     """
     Test remove_dhcp_host action raises exception
     """
     with pytest.raises(
             RuntimeError,
             message=
             'action should raise an error if configure_dhcp raises an exception'
     ):
         networks = [{
             'name': 'network',
             'dhcpserver': {
                 'hosts': [{
                     'macaddress': 'address1'
                 }]
             }
         }]
         self.valid_data['networks'] = networks
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw._gateway_sal.configure_dhcp.side_effect = RuntimeError
         gw.remove_dhcp_host('network', {'macaddress': 'address1'})
         assert gw.data['networks'] == networks
         assert gw._gateway_sal.configure_dhcp.call_count == 2
         assert gw._gateway_sal.configure_cloudinit.call_count == 2
Ejemplo n.º 15
0
 def test_add_dhcp_host(self):
     """
     Test add_dhcp_host action
     """
     self.valid_data['networks'] = [{
         'name': 'network',
         'dhcpserver': {
             'hosts': [{
                 'macaddress': 'address1'
             }]
         }
     }]
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'start', 'ok')
     gw.add_dhcp_host('network', {'macaddress': 'address2'})
     assert gw.data['networks'] == [{
         'name': 'network',
         'dhcpserver': {
             'hosts': [{
                 'macaddress': 'address1'
             }, {
                 'macaddress': 'address2'
             }]
         }
     }]
     gw._gateway_sal.configure_dhcp.assert_called_once_with()
     gw._gateway_sal.configure_cloudinit.assert_called_once_with()
Ejemplo n.º 16
0
    def subscribe(self, req:OrderRequest ):
        """
        Subscribe tick data update of a specific gateway.
        """


        gateway = Gateway(self.event_engine,req.symbol, req.exchange)
        gateway.generate_Tick()
Ejemplo n.º 17
0
def application(config=None):
    """
    used by a WSGI server (ex: gunicorn)

    :param config: if there is no config, the system will use 
    the default configuration :class:`gateway.config.DefaultConfig`.
    """
    return Gateway(__name__, config=config)
Ejemplo n.º 18
0
    def add_gateway(self, gateway_type, credentials=None):
        credentials = credentials or {}

        body = self.add_gateway_body(gateway_type, credentials)
        xml_doc = ssl_requester.ssl_post(urls.add_gateway_url(), body,
                                         self.headers)

        return Gateway(xml_doc)
Ejemplo n.º 19
0
 def test_stop(self):
     """
     Test uninstall action
     """
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'start', 'ok')
     gw.stop()
     gw._gateway_sal.stop.called_once_with()
Ejemplo n.º 20
0
 def test_start(self):
     """
     Test start action
     """
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'install', 'ok')
     gw.install = MagicMock()
     gw.start()
     gw.install.assert_called_once_with()
Ejemplo n.º 21
0
    def test_node_sal(self):
        """
        Test _node_sal property
        """
        get_node = patch('jumpscale.j.clients.zos.get',
                         MagicMock(return_value='node_sal')).start()
        gw = Gateway('gw', data=self.valid_data)

        assert gw._node_sal == 'node_sal'
        get_node.assert_called_once_with(NODE_CLIENT)
Ejemplo n.º 22
0
 def test_add_network(self):
     """
     Test add_network action
     """
     network = {'name': 'network', 'type': 'default', 'id': 'id'}
     gw = Gateway('gw', data=self.valid_data)
     gw.state.set('actions', 'start', 'ok')
     gw.add_network(network)
     assert gw.data['networks'] == [network]
     gw._gateway_sal.deploy.assert_called_once_with()
Ejemplo n.º 23
0
 def test_start_not_installed(self):
     """
     Test start action, gateway isnt installed
     """
     with pytest.raises(
             StateCheckError,
             message=
             'actions should raise an error if gateway isn\'t installed'):
         gw = Gateway('gw', data=self.valid_data)
         gw.start()
Ejemplo n.º 24
0
 def test_remove_network_before_start(self):
     """
     Test remove_network action if gateway isn't started
     """
     with pytest.raises(
             StateCheckError,
             message=
             'action should raise an error if another gateway isnt started'
     ):
         gw = Gateway('gw', data=self.valid_data)
         gw.remove_network('network')
Ejemplo n.º 25
0
    def test_gateway_sal(self):
        """
        Test _gateway_sal property
        """
        gw = Gateway('gw', data=self.valid_data)
        gw_sal = MagicMock()
        gw._node_sal.primitives.from_dict.return_value = gw_sal

        assert gw._gateway_sal == gw_sal
        gw._node_sal.primitives.from_dict.assert_called_once_with(
            'gateway', self.valid_data)
Ejemplo n.º 26
0
 def test_remove_dhcp_host_name_doesnt_exists(self):
     """
     Test remove_dhcp_host action if network with name doesnt exist
     """
     with pytest.raises(
             LookupError,
             message=
             'action should raise an error if network with this name doesnt exist'
     ):
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw.remove_dhcp_host('network', {'macaddress': 'address2'})
Ejemplo n.º 27
0
 def test_add_network_before_start(self):
     """
     Test add_network action if gateway isn't started
     """
     with pytest.raises(
             StateCheckError,
             message=
             'action should raise an error if another network with the same type and id combination exists'
     ):
         network = {'name': 'network', 'type': 'default', 'id': 'id'}
         gw = Gateway('gw', data=self.valid_data)
         gw.add_network(network)
Ejemplo n.º 28
0
 def test_install(self):
     """
     Test install action
     """
     gw = Gateway('gw', data=self.valid_data)
     gw_sal = MagicMock(zt_identity='zt_identity')
     gw._node_sal.primitives.from_dict.return_value = gw_sal
     gw.install()
     gw_sal.deploy.assert_called_once_with()
     assert gw.data['ztIdentity'] == 'zt_identity'
     gw.state.check('actions', 'install', 'ok')
     gw.state.check('actions', 'start', 'ok')
Ejemplo n.º 29
0
    def _mock_service(self, data, mock_capacity=True):
        self.service = Gateway(name='service', data=data)
        self.robotapi = MagicMock()
        self.vmservice = MagicMock()
        self.service.api.services.get = MagicMock(return_value=self.vmservice)
        self.publibcrobotapi = MagicMock()
        self.gateway = MagicMock()
        self.public_gateway = MagicMock()
        self.robotapi.services.get.return_value = self.gateway
        self.robotapi.services.find_or_create.return_value = self.gateway
        self.publibcrobotapi.services.get.return_value = self.public_gateway
        self.publibcrobotapi.services.find_or_create.return_value = self.public_gateway
        kwargs = {NODEID: self.robotapi}
        for url in PUBLIC_GW_ROBOTS:
            key = urlparse(url).netloc
            kwargs[key] = self.publibcrobotapi
        j.clients.zrobot.robots = kwargs
        capacity = MagicMock()
        self.mocknode = MagicMock(robot_address='url')
        capacity.api.GetCapacity.return_value = (self.mocknode, None)
        j.clients.grid_capacity.get.return_value = capacity

        # public gateay info
        self.public_gateway_info = {
            'httpproxies': [],
            'zerotierId': 'abcdef1234567890'
        }
        self.public_gateway.schedule_action.return_value.wait.return_value.result = self.public_gateway_info

        # gateway network
        self.gateway_info = {
            'networks': [{
                'public': True,
                'config': {
                    'cidr': '172.18.0.1/16'
                }
            }],
            'portforwards': []
        }

        self.gateway.schedule_action.return_value.wait.return_value.result = self.gateway_info
        # vm info
        self.vmservice.schedule_action.return_value.wait.return_value.result = {
            'zerotier': {
                'id': PRIVATEZT,
                'ztClient': 'main',
            },
            'ztIdentity': 'abcdef:423423'
        }
Ejemplo n.º 30
0
 def test_add_network_name_exist_same_combination(self):
     """
     Test add_network action if network with the same type and id combination exists
     """
     with pytest.raises(
             ValueError,
             message=
             'action should raise an error if another network with the same type and id combination exists'
     ):
         network = {'name': 'network', 'type': 'default', 'id': 'id'}
         network_two = {'name': 'network2', 'type': 'default', 'id': 'id'}
         self.valid_data['networks'].append(network)
         gw = Gateway('gw', data=self.valid_data)
         gw.state.set('actions', 'start', 'ok')
         gw.add_network(network_two)