How to use the scenario.load_scenario function in scenario

To help you get started, we’ve selected a few scenario examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Orange-OpenSource / diafuzzer / fuzz-proprietary-avps.py View on Github external
help="Define the mode of the fuzzing. Either as a client to fuzz a server, or as a server to fuzz clients. (default: client)")
    parser.add_argument('--min', type=int, default=0, help="The minimum AVP code to scan (default: 0)")
    parser.add_argument('--max', type=int, default=2**24, help="The maximum AVP code to scan (default: 2^24)")
    parser.add_argument('--vendor', type=int, default=0, help="The vendor ID to fuzz (default: 0)")
    parser.add_argument('--local-hostname', type=str, default='mme.openair4G.eur', help="Define the local hostname to use in the scenario (default=mme.openair4G.eur)")
    parser.add_argument('--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)
        start = time.ctime()
        startT = time.time()
github Orange-OpenSource / diafuzzer / fuzz.py View on Github external
# parse additional argument in client or clientloop modes
  target = None
  if args.mode in ('client', 'clientloop'):
    if len(args.remote) != 1 or len(args.remote[0]) == 0:
      parser.print_help()
      print >>sys.stderr, 'using client or clientloop modes require to specify target IP:port'
      sys.exit(1)

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


  # load scenario
  scenario = load_scenario(args.scenario, args.local_hostname, args.local_realm)


  logging.basicConfig(format='%(asctime)s %(message)s', level=logging.WARNING)

  if args.mode == 'client':
    # run once in order to capture exchanged pdus
    f = sk.socket(sk.AF_INET, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
    if args.local_addresses:
      addrs = [(a, 0) for a in args.local_addresses]
      ret = sctp.bindx(f, addrs)
      assert(ret == 0)
    else:
      f.bind(('0.0.0.0', args.local_port))
    f.connect((host, port))

    (exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm)
github Orange-OpenSource / diafuzzer / unit.py View on Github external
else:
      ADDR_ANY = '::'

  # parse additional argument in client or clientloop modes
  target = None
  if args.mode in ('client', 'clientloop'):
    if len(args.remote) != 2 or len(args.remote[0]) == 0:
      parser.print_help()
      print >>sys.stderr, 'using client or clientloop modes require to specify target ip port'
      sys.exit(1)

    target = args.remote[0]
    port = int(args.remote[1])

  # load scenario
  scenario = load_scenario(args.scenario, args.local_hostname, args.local_realm)

  if args.mode in ('client', 'clientloop'):
    while True:
      f = sk.socket(family, sk.SOCK_STREAM, sk.IPPROTO_SCTP)
      if args.local_addresses:
        addrs = [(a, int(args.local_port)) for a in args.local_addresses]
        ret = sctp.bindx(f, addrs, family)
        assert(ret == 0)
      else:
        f.bind((ADDR_ANY, args.local_port))

      f.connect((target, port))

      (exc_info, msgs) = dwr_handler(scenario, f, args.local_hostname, args.local_realm)
      if exc_info is not None:
        print('raised: %s' % (exc_info))
github eclipse / sumo / tools / contributed / sumopy / coremodules / scenario / wxgui.py View on Github external
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())
github eclipse / sumo / tools / contributed / sumopy / coremodules / scenario / wxgui.py View on Github external
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()
github eclipse / sumo / sumo / tools / contributed / sumopy / coremodules / scenario / wxgui.py View on Github external
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()
github eclipse / sumo / sumo / tools / contributed / sumopy / coremodules / scenario / wxgui.py View on Github external
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())