コード例 #1
0
 def __init__(self, server_id, conf_dir, public=None, bind=None):
     """
     :param str server_id: server identifier.
     :param str conf_dir: configuration directory.
     :param list public:
         (host_addr, port) of the element's public address
         (i.e. the address visible to other network elements).
     :param list bind:
         (host_addr, port) of the element's bind address, if any
         (i.e. the address the element uses to identify itself to the local
         operating system, if it differs from the public address due to NAT).
     """
     self.id = server_id
     self.conf_dir = conf_dir
     self.ifid2br = {}
     self.topology = Topology.from_file(
         os.path.join(self.conf_dir, TOPO_FILE))
     self.config = Config.from_file(
         os.path.join(self.conf_dir, AS_CONF_FILE))
     # Must be over-ridden by child classes:
     self.CTRL_PLD_CLASS_MAP = {}
     self.SCMP_PLD_CLASS_MAP = {}
     self.public = public
     self.bind = bind
     if self.SERVICE_TYPE:
         own_config = self.topology.get_own_config(self.SERVICE_TYPE,
                                                   server_id)
         if public is None:
             self.public = own_config.public
         if bind is None:
             self.bind = own_config.bind
     self.init_ifid2br()
     self.trust_store = TrustStore(self.conf_dir)
     self.total_dropped = 0
     self._core_ases = defaultdict(
         list)  # Mapping ISD_ID->list of core ASes
     self.init_core_ases()
     self.run_flag = threading.Event()
     self.run_flag.set()
     self.stopped_flag = threading.Event()
     self.stopped_flag.clear()
     self._in_buf = queue.Queue(MAX_QUEUE)
     self._socks = SocketMgr()
     self._startup = time.time()
     if self.USE_TCP:
         self._DefaultMeta = TCPMetadata
     else:
         self._DefaultMeta = UDPMetadata
     self.unverified_segs = set()
     self.unv_segs_lock = threading.RLock()
     self.requested_trcs = {}
     self.req_trcs_lock = threading.Lock()
     self.requested_certs = {}
     self.req_certs_lock = threading.Lock()
     # TODO(jonghoonkwon): Fix me to setup sockets for multiple public addresses
     host_addr, self._port = self.public[0]
     self.addr = SCIONAddr.from_values(self.topology.isd_as, host_addr)
     self._setup_sockets(True)
コード例 #2
0
 def test_add_non_unique_version(self, write_file):
     inst = TrustStore("conf_dir")
     inst._certs[(1, 1)] = [(0, 'cert0'), (1, 'cert1')]
     certs_before = inst._certs[(1, 1)][:]
     cert = create_mock(['get_leaf_isd_as_ver'])
     cert.get_leaf_isd_as_ver.return_value = ((1, 1), 1)
     # Call
     inst.add_cert(cert)
     # Tests
     ntools.eq_(inst._certs[(1, 1)], certs_before)
     ntools.assert_false(write_file.called)
コード例 #3
0
 def test_add_non_unique_version(self, write_file):
     inst = TrustStore("conf_dir")
     inst._trcs[1] = [(0, 'trc0'), (1, 'trc1')]
     trcs_before = inst._trcs[1][:]
     trc = create_mock(['get_isd_ver'])
     trc.get_isd_ver.return_value = (1, 1)
     # Call
     inst.add_trc(trc)
     # Tests
     ntools.eq_(inst._trcs[1], trcs_before)
     ntools.assert_false(write_file.called)
コード例 #4
0
 def test_add_unique_version(self, write_file):
     inst = TrustStore("conf_dir")
     inst._trcs[1] = [(0, 'trc0'), (1, 'trc1')]
     trcs_before = inst._trcs[1][:]
     trc = create_mock(['get_isd_ver'])
     trc.get_isd_ver.return_value = (1, 2)
     # Call
     inst.add_trc(trc)
     # Tests
     ntools.eq_(inst._trcs[1], trcs_before + [(2, trc)])
     write_file.assert_called_once_with("conf_dir/certs/ISD1-V2.trc",
                                        str(trc))
コード例 #5
0
 def test_add_unique_version(self, write_file):
     inst = TrustStore("conf_dir")
     inst._certs[(1, 1)] = [(0, 'cert0'), (1, 'cert1')]
     certs_before = inst._certs[(1, 1)][:]
     cert = create_mock(['get_leaf_isd_as_ver'])
     cert.get_leaf_isd_as_ver.return_value = ((1, 1), 2)
     # Call
     inst.add_cert(cert)
     # Tests
     ntools.eq_(inst._certs[(1, 1)], certs_before + [(2, cert)])
     write_file.assert_called_once_with("conf_dir/certs/ISD1-AS1-V2.crt",
                                        str(cert))
コード例 #6
0
ファイル: trust_store_test.py プロジェクト: xabarass/scion
 def test_add_non_unique_version(self, write_file):
     inst = TrustStore("conf_dir", "cache_dir", "element_name")
     ia = ISD_AS("1-ff00:0:1")
     inst._certs[ia] = [(0, 'cert0'), (1, 'cert1')]
     certs_before = inst._certs[ia][:]
     cert = create_mock(['get_leaf_isd_as_ver'])
     cert.get_leaf_isd_as_ver.return_value = (ia, 1)
     # Call
     inst.add_cert(cert)
     # Tests
     ntools.eq_(inst._certs[ia], certs_before)
     ntools.assert_false(write_file.called)
コード例 #7
0
ファイル: scion_elem.py プロジェクト: sasjafor/scion
 def __init__(self,
              server_id: str,
              conf_dir: str,
              host_addr: HostAddrBase = None,
              port: int = None) -> None:
     """
     :param str server_id: server identifier.
     :param str conf_dir: configuration directory.
     :param `HostAddrBase` host_addr:
         the interface to bind to. Overrides the address in the topology
         config.
     :param int port:
         the port to bind to. Overrides the address in the topology config.
     """
     self.id = server_id
     self.conf_dir = conf_dir
     self.ifid2br = {}  # type: Dict[int, RouterElement]
     self._port = port
     self.topology = Topology.from_file(
         os.path.join(self.conf_dir, TOPO_FILE))
     self.config = Config.from_file(
         os.path.join(self.conf_dir, AS_CONF_FILE))
     # Must be over-ridden by child classes:
     # self.CTRL_PLD_CLASS_MAP = {}  # type: Dict[str, Dict[Optional[int], Callable[[object, object, object], None]]]
     # self.SCMP_PLD_CLASS_MAP = {}  # type: Dict[int, Dict[Optional[int], Callable[[object, object], None]]]
     if self._service_type():
         own_config = self.topology.get_own_config(self._service_type(),
                                                   server_id)
         if host_addr is None:
             host_addr = own_config.addr
         if self._port is None:
             self._port = own_config.port
     self.addr = SCIONAddr.from_values(self.topology.isd_as,
                                       host_addr)  # type: SCIONAddr
     self.init_ifid2br()
     self.trust_store = TrustStore(self.conf_dir)
     self.total_dropped = 0
     self._core_ases = defaultdict(
         list_object
     )  # type: defaultdict[int, List[object]] # Mapping ISD_ID->list of core ASes
     self.init_core_ases()
     self.run_flag = threading.Event()
     self.run_flag.set()
     self.stopped_flag = threading.Event()
     self.stopped_flag.clear()
     self._in_buf = queue.Queue(MAX_QUEUE)  # type: queue.Queue[object]
     self._socks = SocketMgr()
     self._setup_sockets(True)
     self._startup = time.time()
     if SCIONElement.USE_TCP:
         self.DefaultMeta = TCPMetadata  # type: Type[MetadataBase]
     else:
         self.DefaultMeta = UDPMetadata
コード例 #8
0
 def __init__(self, server_id, conf_dir, host_addr=None, port=None):
     """
     :param str server_id: server identifier.
     :param str conf_dir: configuration directory.
     :param `HostAddrBase` host_addr:
         the interface to bind to. Overrides the address in the topology
         config.
     :param int port:
         the port to bind to. Overrides the address in the topology config.
     """
     self.id = server_id
     self.conf_dir = conf_dir
     self.ifid2br = {}
     self._port = port
     self.topology = Topology.from_file(
         os.path.join(self.conf_dir, TOPO_FILE))
     self.config = Config.from_file(
         os.path.join(self.conf_dir, AS_CONF_FILE))
     # Must be over-ridden by child classes:
     self.CTRL_PLD_CLASS_MAP = {}
     self.SCMP_PLD_CLASS_MAP = {}
     if self.SERVICE_TYPE:
         own_config = self.topology.get_own_config(self.SERVICE_TYPE,
                                                   server_id)
         if host_addr is None:
             host_addr = own_config.addr
         if self._port is None:
             self._port = own_config.port
     self.addr = SCIONAddr.from_values(self.topology.isd_as, host_addr)
     self.init_ifid2br()
     self.trust_store = TrustStore(self.conf_dir)
     self.total_dropped = 0
     self._core_ases = defaultdict(list)  # Mapping ISD_ID->list of core ASes
     self.init_core_ases()
     self.run_flag = threading.Event()
     self.run_flag.set()
     self.stopped_flag = threading.Event()
     self.stopped_flag.clear()
     self._in_buf = queue.Queue(MAX_QUEUE)
     self._socks = SocketMgr()
     self._setup_sockets(True)
     self._startup = time.time()
     if self.USE_TCP:
         self.DefaultMeta = TCPMetadata
     else:
         self.DefaultMeta = UDPMetadata
     self.unverified_segs = set()
     self.unv_segs_lock = threading.RLock()
     self.requested_trcs = set()
     self.req_trcs_lock = threading.Lock()
     self.requested_certs = set()
     self.req_certs_lock = threading.Lock()
コード例 #9
0
ファイル: trust_store_test.py プロジェクト: xabarass/scion
 def test_add_unique_version(self, write_file):
     inst = TrustStore("conf_dir", "cache_dir", "element_name")
     ia = ISD_AS("1-ff00:0:1")
     inst._certs[ia] = [(0, 'cert0'), (1, 'cert1')]
     certs_before = inst._certs[ia][:]
     cert = create_mock(['get_leaf_isd_as_ver'])
     cert.get_leaf_isd_as_ver.return_value = (ia, 2)
     # Call
     inst.add_cert(cert)
     # Tests
     ntools.eq_(inst._certs[ia], certs_before + [(2, cert)])
     write_file.assert_called_once_with(
         "cache_dir/element_name-ISD1-ASff00_0_1-V2.crt", str(cert))
コード例 #10
0
ファイル: scion_elem.py プロジェクト: jpcsmith/scion-old
 def __init__(self,
              server_id,
              conf_dir,
              host_addr=None,
              port=SCION_UDP_PORT):
     """
     :param str server_id: server identifier.
     :param str conf_dir: configuration directory.
     :param `HostAddrBase` host_addr:
         the interface to bind to. Overrides the address in the topology
         config.
     :param int port: the port to bind to.
     """
     self.id = server_id
     self.conf_dir = conf_dir
     self.ifid2er = {}
     self._port = port
     self.topology = Topology.from_file(
         os.path.join(self.conf_dir, TOPO_FILE))
     self.config = Config.from_file(
         os.path.join(self.conf_dir, AS_CONF_FILE))
     # Must be over-ridden by child classes:
     self.CTRL_PLD_CLASS_MAP = {}
     self.SCMP_PLD_CLASS_MAP = {}
     if host_addr is None:
         own_config = self.topology.get_own_config(self.SERVICE_TYPE,
                                                   server_id)
         host_addr = own_config.addr
     self.addr = SCIONAddr.from_values(self.topology.isd_as, host_addr)
     self._dns = DNSCachingClient(
         [str(s.addr) for s in self.topology.dns_servers],
         self.topology.dns_domain)
     self.init_ifid2er()
     self.trust_store = TrustStore(self.conf_dir)
     self.total_dropped = 0
     self._core_ases = defaultdict(
         list)  # Mapping ISD_ID->list of core ASes
     self.init_core_ases()
     self.run_flag = threading.Event()
     self.run_flag.set()
     self.stopped_flag = threading.Event()
     self.stopped_flag.clear()
     self._in_buf = queue.Queue(MAX_QUEUE)
     self._socks = SocketMgr()
     self._setup_socket(True)
     self._startup = time.time()
コード例 #11
0
 def _init(self):
     inst = TrustStore("conf_dir")
     inst._certs["1-1"] = [(1, 'cert1'), (3, 'cert3'), (0, 'cert0')]
     return inst
コード例 #12
0
 def _init(self):
     inst = TrustStore("conf_dir")
     inst._trcs[1] = [(1, 'trc1'), (3, 'trc3'), (0, 'trc0')]
     return inst
コード例 #13
0
 def _init(self):
     inst = TrustStore("conf_dir", "cache_dir", "element_name")
     inst._certs["1-1"] = [(1, 'cert1'), (3, 'cert3'), (0, 'cert0')]
     return inst
コード例 #14
0
 def _init(self):
     inst = TrustStore("conf_dir", "cache_dir", "element_name")
     inst._trcs[1] = [(1, 'trc1'), (3, 'trc3'), (0, 'trc0')]
     return inst
コード例 #15
0
ファイル: scion_elem.py プロジェクト: stschwar/scion
 def __init__(self, server_id, conf_dir, public=None, bind=None, spki_cache_dir=GEN_CACHE_PATH,
              prom_export=None):
     """
     :param str server_id: server identifier.
     :param str conf_dir: configuration directory.
     :param list public:
         (host_addr, port) of the element's public address
         (i.e. the address visible to other network elements).
     :param list bind:
         (host_addr, port) of the element's bind address, if any
         (i.e. the address the element uses to identify itself to the local
         operating system, if it differs from the public address due to NAT).
     :param str spki_cache_dir:
         Path for caching TRCs and certificate chains.
     :param str prom_export:
         String of the form 'addr:port' specifying the prometheus endpoint.
         If no string is provided, no metrics are exported.
     """
     self.id = server_id
     self.conf_dir = conf_dir
     self.ifid2br = {}
     self.topology = Topology.from_file(
         os.path.join(self.conf_dir, TOPO_FILE))
     # Labels attached to every exported metric.
     self._labels = {"server_id": self.id, "isd_as": str(self.topology.isd_as)}
     # Must be over-ridden by child classes:
     self.CTRL_PLD_CLASS_MAP = {}
     self.SCMP_PLD_CLASS_MAP = {}
     self.public = public
     self.bind = bind
     if self.SERVICE_TYPE:
         own_config = self.topology.get_own_config(self.SERVICE_TYPE,
                                                   server_id)
         if public is None:
             self.public = own_config.public
         if bind is None:
             self.bind = own_config.bind
     self.init_ifid2br()
     self.trust_store = TrustStore(self.conf_dir, spki_cache_dir, self.id, self._labels)
     self.total_dropped = 0
     self._core_ases = defaultdict(list)  # Mapping ISD_ID->list of core ASes
     self.init_core_ases()
     self.run_flag = threading.Event()
     self.run_flag.set()
     self.stopped_flag = threading.Event()
     self.stopped_flag.clear()
     self._in_buf = queue.Queue(MAX_QUEUE)
     self._socks = SocketMgr()
     self._startup = time.time()
     if self.USE_TCP:
         self._DefaultMeta = TCPMetadata
     else:
         self._DefaultMeta = UDPMetadata
     self.unverified_segs = ExpiringDict(500, 60 * 60)
     self.unv_segs_lock = threading.RLock()
     self.requested_trcs = {}
     self.req_trcs_lock = threading.Lock()
     self.requested_certs = {}
     self.req_certs_lock = threading.Lock()
     # TODO(jonghoonkwon): Fix me to setup sockets for multiple public addresses
     host_addr, self._port = self.public[0]
     self.addr = SCIONAddr.from_values(self.topology.isd_as, host_addr)
     if prom_export:
         self._export_metrics(prom_export)
         self._init_metrics()
     self._setup_sockets(True)
     lib_sciond.init(os.path.join(SCIOND_API_SOCKDIR, "sd%s.sock" % self.addr.isd_as))