Esempio n. 1
0
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
}
Esempio n. 2
0
func (c *cmdEfhSuite) RunTest(testDirName string, suffix *string) (err error) {
	defer errs.Catch(func(ce errs.CheckerError) {
		log.Printf("caught %s\n", ce)
		err = ce
	})
	c.testRunsTotal++
	testRunName := time.Now().Format("2006-01-02-15:04:05.")
	tdnDir, tdnFile := filepath.Split(testDirName)
	tdnDir = filepath.Base(tdnDir)
	testRunName += tdnDir + "-" + tdnFile
	if suffix != nil {
		testRunName += *suffix
	}
	fmt.Printf("run %s\n", testRunName)
	outDirName := filepath.Join(c.topOutDirName, testRunName)
	expoutName := filepath.Join(testDirName, "expout-efh-orders")
	if suffix != nil {
		expoutName += *suffix
	}
	inputPcapName := filepath.Join(testDirName, "dump.pcap")
	_, err = os.Stat(expoutName)
	errs.CheckE(err)
	_, err = os.Stat(inputPcapName)
	errs.CheckE(err)
	errs.CheckE(os.MkdirAll(outDirName, 0777))
	errs.CheckE(ioutil.WriteFile(filepath.Join(outDirName, "fail"), nil, 0666))
	efhDumpName := filepath.Join(outDirName, "expout_orders")
	errs.CheckE(os.Symlink(expoutName, efhDumpName))
	errs.CheckE(os.Symlink(testDirName, filepath.Join(outDirName, "dump_dir")))
	errs.CheckE(os.Symlink(inputPcapName, filepath.Join(outDirName, "dump.pcap")))
	conf := efh.ReplayConfig{
		InputFileName:   inputPcapName,
		OutputInterface: "eth1",
		Pps:             c.Speed,
		Limit:           c.Limit,
		Loop:            1,
		EfhLoglevel:     c.EfhLoglevel,
		EfhIgnoreGap:    true,
		EfhDump:         "expout_orders",
		EfhChannel:      c.genEfhChannels(testDirName),
		EfhProf:         c.EfhProf,
		RegConfig:       c.regConfig,
		TestEfh:         c.TestEfh,
		Local:           c.Local,
	}
	if suffix != nil {
		subscr := "subscription" + *suffix
		errs.CheckE(os.Symlink(filepath.Join(testDirName, subscr), filepath.Join(outDirName, subscr)))
		conf.EfhSubscribe = []string{subscr}
	}
	origWd, err := os.Getwd()
	errs.CheckE(err)
	errs.CheckE(os.Chdir(outDirName))
	er := efh.NewEfhReplay(conf)
	efhReplayErr := er.Run()
	errs.CheckE(os.Chdir(origWd))
	errs.CheckE(efhReplayErr)
	errs.CheckE(ioutil.WriteFile(filepath.Join(outDirName, "ok"), nil, 0666))
	errs.CheckE(os.Remove(filepath.Join(outDirName, "fail")))
	c.testRunsOk++
	return
}