コード例 #1
0
ファイル: bats.go プロジェクト: ikravets/ev
func (s *spinServerConn) run() {
	defer errs.Catch(func(ce errs.CheckerError) {
		log.Printf("caught %s\n", ce)
	})
	defer s.conn.Close()
	errs.CheckE(s.login())
	cancelSendImageAvail := make(chan struct{})
	defer func() {
		// close channel only if not already closed
		select {
		case _, ok := <-cancelSendImageAvail:
			if !ok {
				return
			}
		default:
		}
		close(cancelSendImageAvail)
	}()
	go s.sendImageAvail(cancelSendImageAvail)

	m, err := s.bconn.ReadMessage()
	errs.CheckE(err)
	req, ok := m.(*bats.MessageSpinRequest)
	errs.Check(ok)
	close(cancelSendImageAvail)

	seq := s.src.CurrentSequence()
	errs.Check(int(req.Sequence) <= seq, req.Sequence, seq)
	res := bats.MessageSpinResponse{
		Sequence: req.Sequence,
		Count:    uint32(seq) - req.Sequence + 1,
		Status:   bats.SpinStatusAccepted,
	}
	errs.CheckE(s.bconn.WriteMessageSimple(&res))
	errs.CheckE(s.sendAll(int(req.Sequence), seq+1))
	s.waitForMcast(seq)
	res2 := bats.MessageSpinFinished{
		Sequence: req.Sequence,
	}
	errs.CheckE(s.bconn.WriteMessageSimple(&res2))
	log.Println("spin finished")
}
コード例 #2
0
ファイル: bats.go プロジェクト: ikravets/ev
func (gc *gapProxyConn) run() {
	defer errs.Catch(func(ce errs.CheckerError) {
		log.Printf("caught %s\n", ce)
	})
	defer gc.conn.Close()
	errs.CheckE(gc.login())

	m, err := gc.bconn.ReadMessage()
	errs.CheckE(err)
	req, ok := m.(*bats.MessageGapRequest)
	errs.Check(ok)
	res := bats.MessageGapResponse{
		Unit:     req.Unit,
		Sequence: req.Sequence,
		Count:    req.Count,
		Status:   bats.GapStatusAccepted,
	}
	errs.CheckE(gc.bconn.WriteMessageSimple(&res))
	gc.noticeGapMultiCast(int(req.Sequence), int(req.Sequence+uint32(req.Count)))
	//	gc.noticeGapMultiCast(5, 12)

	log.Println("gap finished")
}
コード例 #3
0
ファイル: miax.go プロジェクト: ikravets/ev
func (s *SesMServerConn) run() {
	defer errs.Catch(func(ce errs.CheckerError) {
		log.Printf("caught %s\n", ce)
	})
	sendLastMessages := func(endSession bool) {
		if endSession {
			errs.CheckE(s.mconn.WriteMessageSimple(&miax.SesMEndOfSession{}))
		}
		errs.CheckE(s.mconn.WriteMessageSimple(&miax.SesMGoodBye{Reason: miax.GoodByeReasonTerminating}))
	}
	defer func() {
		s.conn.Close()
		log.Println("sesm finished")
	}()
	if err := s.login(); err != nil {
		sendLastMessages(false)
		errs.CheckE(err)
	}
	cancelSendHeartbeat := make(chan struct{})
	defer func() {
		// close channel only if not already closed
		select {
		case _, ok := <-cancelSendHeartbeat:
			if !ok {
				return
			}
		default:
		}
		close(cancelSendHeartbeat)
	}()
	go s.sendHeartbeat(cancelSendHeartbeat)

	for {
		m, err := s.mconn.ReadMessage()
		if err == io.EOF {
			sendLastMessages(true)
			return
		}
		errs.CheckE(err)

		mtype := m.Type()
		switch mtype {
		case miax.TypeSesMRetransmRequest:
			rt, ok := m.(*miax.SesMRetransmRequest)
			errs.Check(ok)
			errs.CheckE(s.sendAll(rt.StartSeqNumber, rt.EndSeqNumber))
			sendLastMessages(true)
			return
		case miax.TypeSesMUnseq:
			rf, ok := m.(*miax.SesMRefreshRequest)
			errs.Check(ok)
			errs.Check(rf.RefreshType == miax.SesMRefreshToM || rf.RefreshType == miax.SesMRefreshSeriesUpdate)
			// send miax system time first! (ToM 1.8, 3.2.2.2 note)
			sn := uint64(s.src.CurrentSequence())
			stime := &miax.MachSystemTime{TimeStamp: uint32(sn)}
			stime.SetType(stime.GetType())
			errs.CheckE(s.mconn.WriteMachMessage(sn-2, stime))
			errs.CheckE(s.mconn.WriteMachMessage(sn-1, s.src.generateRefreshResponse(rf.RefreshType, 5)))
			errs.CheckE(s.mconn.WriteMachMessage(sn, s.src.generateRefreshResponse(rf.RefreshType, 6)))
			eor := miax.SesMEndRefreshNotif{
				RefreshType:  rf.RefreshType,
				ResponseType: 'E',
			}
			errs.CheckE(s.mconn.WriteMessageSimple(&eor))
		case miax.TypeSesMClientHeartbeat:
		default:
			sendLastMessages(true)
			return
		}
	}
}
コード例 #4
0
ファイル: efh_suite.go プロジェクト: ikravets/ev
func (c *cmdEfhSuite) ParsingFinished() (err error) {
	defer errs.Catch(func(ce errs.CheckerError) {
		log.Printf("caught %s\n", ce)
	})
	if !c.shouldExecute {
		return
	}
	c.topOutDirName = time.Now().Format("efh_regression.2006-01-02-15:04:05")
	suitesDirName := fmt.Sprintf("/local/dumps/%s/regression", c.Exchange)

	if len(c.Suites) == 0 || c.Suites[0] == "?" {
		suites, err2 := listDirs(suitesDirName)
		errs.CheckE(err2)
		if len(c.Suites) > 0 {
			fmt.Printf("suites: %s\n", suites)
			return
		}
		if len(suites) == 0 {
			log.Println("Warning: no suites found")
			return
		}
		c.Suites = suites
	}

	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)))
	}

	for _, suite := range c.Suites {
		var suiteDirName string
		if strings.HasPrefix(suite, "/") {
			suiteDirName = suite
		} else if strings.HasPrefix(suite, "./") {
			cwd, err := os.Getwd()
			errs.CheckE(err)
			suiteDirName = filepath.Join(cwd, suite)
		} else {
			suiteDirName = filepath.Join(suitesDirName, suite)
		}
		var tests []string
		if len(c.Tests) == 0 || c.Tests[0] == "?" {
			tests, err = listDirs(suiteDirName)
			errs.CheckE(err)
			if len(c.Tests) > 0 {
				fmt.Printf("suite %s tests: %v\n", suiteDirName, tests)
				continue
			}
		} else {
			tests = c.Tests
		}
		if len(tests) == 0 {
			log.Printf("Warning: no tests found in suite %s\n", suite)
			continue
		}

		for _, testName := range tests {
			testDirName := filepath.Join(suiteDirName, testName)
			subscriptionFileNames, err := filepath.Glob(filepath.Join(testDirName, "subscription*"))
			errs.CheckE(err)
			if len(subscriptionFileNames) == 0 {
				c.RunTest(testDirName, nil)
			} else {
				for _, sfn := range subscriptionFileNames {
					a := strings.SplitAfter(sfn, "/subscription")
					suf := ""
					if len(a) > 0 {
						suf = a[len(a)-1]
					}
					c.RunTest(testDirName, &suf)
				}
			}
		}
	}
	log.Printf("Tests OK/Total: %d/%d\n", c.testRunsOk, c.testRunsTotal)
	fmt.Printf("Tests OK/Total: %d/%d\n", c.testRunsOk, c.testRunsTotal)
	return
}
コード例 #5
0
ファイル: efh_suite.go プロジェクト: ikravets/ev
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
}