示例#1
0
文件: efh_suite.go 项目: ikravets/ev
func (c *cmdEfhSuite) genEfhChannels(testDirName string) (cc channels.Config) {
	cc = channels.NewConfig()
	if file, err := os.Open(filepath.Join(testDirName, "channels")); err == nil {
		defer file.Close()
		errs.CheckE(cc.LoadFromReader(file))
	} else {
		errs.CheckE(cc.LoadFromStr(c.Exchange))
	}
	return
}
示例#2
0
文件: efh_replay.go 项目: ikravets/ev
func (c *cmdEfhReplay) ParsingFinished() (err error) {
	if !c.shouldExecute {
		return
	}
	cc := channels.NewConfig()
	for _, s := range c.EfhChannel {
		errs.CheckE(cc.LoadFromStr(s))
	}

	if c.Inspect != "" {
		buf, err := ioutil.ReadFile(c.Inspect)
		errs.CheckE(err)
		dev, err := device.NewEfh_toolDevice()
		errs.CheckE(err)
		c.regConfig = inspect.NewConfig(dev)
		errs.CheckE(c.regConfig.Parse(string(buf)))
	}

	conf := efh.ReplayConfig{
		InputFileName:   c.InputFileName,
		OutputInterface: c.OutputInterface,
		Pps:             c.Pps,
		Limit:           c.Limit,
		Loop:            c.Loop,
		EfhLoglevel:     c.EfhLoglevel,
		EfhIgnoreGap:    c.EfhIgnoreGap,
		EfhDump:         c.EfhDump,
		EfhSubscribe:    c.EfhSubscribe,
		EfhChannel:      cc,
		EfhProf:         c.EfhProf,
		RegConfig:       c.regConfig,
		TestEfh:         c.TestEfh,
		Local:           c.Local,
	}
	er := efh.NewEfhReplay(conf)
	err = er.Run()
	if err != nil {
		log.Printf("ERROR %s", err)
	}
	return
}
示例#3
0
文件: efhsim.go 项目: ikravets/ev
func (c *cmdEfhsim) ParsingFinished() (err error) {
	if !c.shouldExecute {
		return
	}
	efh := efhsim.NewEfhSim(c.TobBook)
	efh.SetInput(c.InputFileName, c.PacketNumLimit)
	if len(c.Channels) > 0 {
		cc := channels.NewConfig()
		for _, s := range c.Channels {
			errs.CheckE(cc.LoadFromStr(s))
		}
		errs.CheckE(efh.RegisterChannels(cc))
	}
	if c.SubscriptionFileName != "" {
		file, err := os.Open(c.SubscriptionFileName)
		errs.CheckE(err)
		errs.CheckE(efh.SubscribeFromReader(file))
		errs.CheckE(file.Close())
	}
	if !c.NoHwLim {
		if efh.SubscriptionsNum() == 0 {
			log.Println("running in auto-subscription mode, not enforcing hw limit")
		} else if efh.SubscriptionsNum() > rec.HwMaxSubscriptions {
			log.Println("too many subscriptions, not enforcing hw limit")
		} else {
			efh.AddLogger(rec.NewHwLimChecker())
		}
	}
	efhLoggerConfig := rec.EfhLoggerConfig{}
	simLoggerConfig := rec.SimLoggerConfig{}
	if c.TobBook {
		efhLoggerConfig.AssumeTobUpdate = true
		simLoggerConfig.AssumeTobUpdate = true
		simLoggerConfig.SupernodeLevels = 1
	}
	c.addOut(c.OutputFileNameSimOrders, func(w io.Writer) error {
		lc := simLoggerConfig
		lc.Writer = w
		lc.Mode = rec.EfhLoggerOutputOrders
		return efh.AddLogger(rec.NewSimLogger(lc))
	})
	c.addOut(c.OutputFileNameSimQuotes, func(w io.Writer) error {
		lc := simLoggerConfig
		lc.Writer = w
		lc.Mode = rec.EfhLoggerOutputQuotes
		return efh.AddLogger(rec.NewSimLogger(lc))
	})
	c.addOut(c.OutputFileNameEfhOrders, func(w io.Writer) error {
		lc := efhLoggerConfig
		lc.Writer = w
		lc.Mode = rec.EfhLoggerOutputOrders
		return efh.AddLogger(rec.NewEfhLogger(lc))
	})
	c.addOut(c.OutputFileNameEfhQuotes, func(w io.Writer) error {
		lc := efhLoggerConfig
		lc.Writer = w
		lc.Mode = rec.EfhLoggerOutputQuotes
		return efh.AddLogger(rec.NewEfhLogger(lc))
	})
	c.addOut(c.OutputFileNameAvt, func(w io.Writer) (err error) {
		defer errs.PassE(&err)
		var dict io.ReadCloser
		if c.InputFileNameAvtDict != "" {
			dict, err := os.Open(c.InputFileNameAvtDict)
			errs.CheckE(err)
			c.closers = append(c.closers, dict)
		}
		return efh.AddLogger(rec.NewAvtLogger(w, dict))
	})
	reporter := c.addAnalyzer(efh)

	// run efhsim
	errs.CheckE(efh.AnalyzeInput())

	for _, cl := range c.closers {
		errs.CheckE(cl.Close())
	}
	if reporter != nil {
		reporter.SaveAll()
	}
	return
}