Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep segments containing ISD-level loops #2046

Merged
merged 4 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions python/beacon_server/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ class CoreBeaconServer(BeaconServer):
towards other core beacon servers.
"""
def __init__(self, server_id, conf_dir, spki_cache_dir=GEN_CACHE_PATH,
prom_export=None, sciond_path=None):
prom_export=None, sciond_path=None, filter_isd_loops=False):
"""
:param str server_id: server identifier.
:param str conf_dir: configuration directory.
:param str prom_export: prometheus export address.
:param str sciond_path: path to sciond socket
:param str filter_isd_loops: filter ISD loops
"""
super().__init__(server_id, conf_dir, spki_cache_dir=spki_cache_dir,
prom_export=prom_export, sciond_path=sciond_path)
# Sanity check that we should indeed be a core beacon server.
assert self.topology.is_core_as, "This shouldn't be a local BS!"
self.core_beacons = defaultdict(self._ps_factory)
self.filter_isd_loops = filter_isd_loops

def _ps_factory(self):
"""
Expand Down Expand Up @@ -155,7 +157,7 @@ def _filter_pcb(self, pcb, dst_ia=None):
continue
# Switched to a new ISD
last_isd = curr_isd
if curr_isd in isds:
if self.filter_isd_loops and curr_isd in isds:
# This ISD has been seen before
return False
isds.add(curr_isd)
Expand Down
45 changes: 43 additions & 2 deletions python/bin/beacon_server
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,50 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Stdlib
import argparse
import logging
import os
# SCION
from beacon_server.core import CoreBeaconServer
from beacon_server.local import LocalBeaconServer
from lib.main import main_default, main_wrapper
from lib.app.sciond import get_default_sciond_path
from lib.defines import TOPO_FILE
from lib.log import init_logging, log_exception
from lib.main import main_wrapper
from lib.topology import Topology
from lib.util import handle_signals, trace

main_wrapper(main_default, CoreBeaconServer, LocalBeaconServer)

def beacon_default():
handle_signals()
parser = argparse.ArgumentParser()
parser.add_argument('--log_dir', default="logs/", help='Log dir (Default: logs/)')
parser.add_argument('--spki_cache_dir', default="gen-cache/",
help='Cache dir for SCION TRCs and cert chains (Default: gen-cache/)')
parser.add_argument('--prom', type=str, help='Address to export prometheus metrics on')
parser.add_argument('--sciond_path', type=str, help='Sciond socket path '
'(Default: %s)' % get_default_sciond_path())
parser.add_argument('--filter_isd_loops', default=False, action='store_true',
help='Filter ISD loops in Core Beacon Server (Default: False)')
parser.add_argument('server_id', help='Server identifier')
parser.add_argument('conf_dir', nargs='?', default='.',
help='Configuration directory (Default: ./)')
args = parser.parse_args()
init_logging(os.path.join(args.log_dir, args.server_id))

# Load the topology to check if this is a core AD or not
topo = Topology.from_file(os.path.join(args.conf_dir, TOPO_FILE))
if topo.is_core_as:
inst = CoreBeaconServer(args.server_id, args.conf_dir, prom_export=args.prom,
sciond_path=args.sciond_path,
spki_cache_dir=args.spki_cache_dir, filter_isd_loops=args.filter_isd_loops)
else:
inst = LocalBeaconServer(args.server_id, args.conf_dir,
prom_export=args.prom,
sciond_path=args.sciond_path,
spki_cache_dir=args.spki_cache_dir)
logging.info("Started %s", args.server_id)
inst.run()

main_wrapper(beacon_default)