Beispiel #1
0
    def on_open(self, event=None):
        wildcards_all = "All files (*.*)|*.*"
        wildcards_obj = "Python binary files (*.obj)|*.obj"
        wildcards = wildcards_obj + "|" + wildcards_all

        # Finally, if the directory is changed in the process of getting files, this
        # dialog is set up to change the current working directory to the path
        # chosen.
        dlg = wx.FileDialog(
            self._mainframe,
            message="Open scenario file",
            #defaultDir = scenario.get_workdirpath(),
            #defaultFile = os.path.join(scenario.get_workdirpath(), scenario.format_ident()+'.obj'),
            wildcard=wildcards,
            style=wx.OPEN | wx.CHANGE_DIR)

        # Show the dialog and retrieve the user response. If it is the OK response,
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            # This returns a Python list of files that were selected.
            filepath = dlg.GetPath()
            if len(filepath) > 0:

                del self._scenario
                self._scenario = scenario.load_scenario(
                    filepath, logger=self._mainframe.get_logger())
                self._mainframe.browse_obj(self._scenario)
                # this should update all widgets for the new scenario!!
                # print 'call self._mainframe.refresh_moduleguis()'
                self._mainframe.refresh_moduleguis()

        # Destroy the dialog. Don't do this until you are done with it!
        # BAD things can happen otherwise!
        dlg.Destroy()
Beispiel #2
0
    def on_open(self, event=None):
        wildcards_all = "All files (*.*)|*.*"
        wildcards_obj = "Python binary files (*.obj)|*.obj"
        wildcards = wildcards_obj+"|"+wildcards_all

        # Finally, if the directory is changed in the process of getting files, this
        # dialog is set up to change the current working directory to the path chosen.
        dlg = wx.FileDialog(
            self._mainframe, message="Open scenario file",
            #defaultDir = scenario.get_workdirpath(),
            #defaultFile = os.path.join(scenario.get_workdirpath(), scenario.format_ident()+'.obj'),
            wildcard=wildcards,
            style=wx.OPEN | wx.CHANGE_DIR
        )

        # Show the dialog and retrieve the user response. If it is the OK response,
        # process the data.
        if dlg.ShowModal() == wx.ID_OK:
            # This returns a Python list of files that were selected.
            filepath = dlg.GetPath()
            if len(filepath) > 0:

                del self._scenario
                self._scenario = scenario.load_scenario(filepath, logger=self._mainframe.get_logger())
                self._mainframe.browse_obj(self._scenario)
                # this should update all widgets for the new scenario!!
                # print 'call self._mainframe.refresh_moduleguis()'
                self._mainframe.refresh_moduleguis()

        # Destroy the dialog. Don't do this until you are done with it!
        # BAD things can happen otherwise!
        dlg.Destroy()
Beispiel #3
0
    def init_widgets(self, mainframe):
        """
        Set mainframe and initialize widgets to various places.
        """
        self._mainframe = mainframe
        #self._neteditor = mainframe.add_view("Network", Neteditor)

        # mainframe.browse_obj(self._module)
        self.make_menu()
        self.make_toolbar()
        args = mainframe.get_args()

        if len(args) == 3:
            # command line provided rootname and dirpath
            rootname = args[1]
            dirpath = args[2]
            name_scenario = rootname
            self._scenario = scenario.Scenario(
                rootname,
                workdirpath=dirpath,
                name_scenario=name_scenario,
                logger=self._mainframe.get_logger())
            self._scenario.import_xml()

        elif len(args) == 2:
            filepath = args[1]
            self._scenario = scenario.load_scenario(
                filepath, logger=self._mainframe.get_logger())
            #self._scenario = cm.load_obj(filepath)

        else:
            # command line provided nothing
            rootname = 'myscenario'
            # None# this means no directory will be created
            # os.path.join(os.path.expanduser("~"),'sumopy','myscenario')
            dirpath = scenario.DIRPATH_SCENARIO
            name_scenario = 'My Scenario'
            self._scenario = scenario.Scenario(
                rootname,
                workdirpath=dirpath,
                name_scenario=name_scenario,
                logger=self._mainframe.get_logger())
Beispiel #4
0
    def init_widgets(self, mainframe):
        """
        Set mainframe and initialize widgets to various places.
        """
        self._mainframe = mainframe
        #self._neteditor = mainframe.add_view("Network", Neteditor)

        # mainframe.browse_obj(self._module)
        self.make_menu()
        self.make_toolbar()
        args = mainframe.get_args()

        if len(args) == 3:
            # command line provided rootname and dirpath
            rootname = args[1]
            dirpath = args[2]
            name_scenario = rootname
            self._scenario = scenario.Scenario(rootname, workdirpath=dirpath,
                                               name_scenario=name_scenario,
                                               logger=self._mainframe.get_logger())
            self._scenario.import_xml()

        elif len(args) == 2:
            filepath = args[1]
            self._scenario = scenario.load_scenario(
                filepath, logger=self._mainframe.get_logger())
            #self._scenario = cm.load_obj(filepath)

        else:
            # command line provided nothing
            rootname = 'myscenario'
            # None# this means no directory will be created
            # os.path.join(os.path.expanduser("~"),'sumopy','myscenario')
            dirpath = scenario.DIRPATH_SCENARIO
            name_scenario = 'My Scenario'
            self._scenario = scenario.Scenario(rootname, workdirpath=dirpath,
                                               name_scenario=name_scenario,
                                               logger=self._mainframe.get_logger())
        '--local-realm',
        type=str,
        default='openair4G.eur',
        help=
        "Define the local realm to use in the scenario (default=openair4G.eur)"
    )
    args = parser.parse_args()

    # Check the min/max values
    assert (args.min >= 0 and args.min < args.max)
    assert (args.max <= 2**24)
    local_hostname = args.local_hostname
    local_realm = args.local_realm

    try:
        scenario = load_scenario(args.scenario, local_hostname, local_realm)
    except:
        print >> sys.stderr, "%s - [ERROR] Unable to load given scenario: %s" % (
            time.ctime(), args.scenario)
        sys.exit(-1)
    vendor = args.vendor
    mode = args.mode
    host = args.target
    port = args.port

    if mode == 'client':
        # Test the scenario once without fuzzing
        msgs = testScn(host, port, scenario)

        for (m, is_sent) in msgs:
            Directory.tag(m)
Beispiel #6
0
        if o in ('-s', '--scenario'):
            scn = a
        if o in ('-m', '--mode'):
            if a not in ['client', 'server']:
                usage(sys.argv[0])
            mode = a
        if o in ('-H', '--local-hostname'):
            local_hostname = a
        if o in ('-R', '--local-realm'):
            local_realm = a

    if len(args) != 1 or local_hostname is None or local_realm is None \
      or scn is None or mode is None:
        usage(sys.argv[0])

    scenario = load_scenario(scn, local_hostname, local_realm)

    (host, port) = args[0].split(':')
    port = int(port)

    if mode == 'client':
        # run once in order to capture exchanged pdus
        f = sk.socket(sk.AF_INET, sk.SOCK_STREAM)
        f.connect((host, port))
        (exc_info, msgs) = dwr_handler(scenario, f, local_hostname,
                                       local_realm)
        if exc_info is not None:
            print('scenario raised: %s' % exc_info)
        f.close()

        for (m, is_sent) in msgs:
Beispiel #7
0
def run(
    scenario_names: List[str],
    force: bool,
    output_dir: str,
    log_level: str,
    debug: bool,
    raise_exceptions: bool,
):
    # Make sure all models run outside of experiments create their data under the
    # assigned benchmark directory
    os.environ["GOBBLI_DIR"] = str(BENCHMARK_DATA_DIR)

    logging.basicConfig(
        level=log_level, format="[%(asctime)s] %(levelname)s - %(name)s: %(message)s"
    )

    output_path = Path(output_dir)
    specs_file = BENCHMARK_SPECS_FILE
    dataset_limit = None
    if debug:
        output_path = BENCHMARK_DEBUG_OUTPUT_DIR
        specs_file = BENCHMARK_DEBUG_SPECS_FILE
        dataset_limit = 50

    output_path.mkdir(exist_ok=True, parents=True)
    specs = load_specs(specs_file)

    if len(scenario_names) == 0:
        scenario_names = list(specs.keys())

    LOGGER.info(f"Running scenarios: {scenario_names}")

    for scenario_name in scenario_names:
        LOGGER.info(f"Loading scenario: {scenario_name}")
        if scenario_name not in ALL_SCENARIOS:
            raise ValueError(
                f"Unknown scenario type: '{scenario_name}'. Valid values are: "
                f"{list(ALL_SCENARIOS.keys())}"
            )
        if scenario_name not in specs:
            raise ValueError(
                f"No spec for scenario named: '{scenario_name}'. Valid values are: "
                f"{list(specs.keys())}"
            )

        spec = specs[scenario_name]
        scenario = load_scenario(
            ALL_SCENARIOS[scenario_name],
            output_path / scenario_name,
            spec.get("params", {}),
            spec.get("runs", []),
            force=force,
            dataset_limit=dataset_limit,
        )

        LOGGER.info(f"Running scenario: {scenario_name}")
        scenario.run(raise_exceptions=raise_exceptions)
        LOGGER.info(f"Scenario complete: {scenario_name}")

    # Remove task input/output saved to disk, but keep model weights in case
    # future runs can re-use them
    gobbli.util.cleanup(force=True)