Exemple #1
0
func ExampleInterpreter_AddDictionaryEntry() {
	s := ipfix.NewSession()
	i := ipfix.NewInterpreter(s)

	entry := ipfix.DictionaryEntry{
		Name:         "someVendorField",
		FieldID:      42,
		EnterpriseID: 123456,
		Type:         ipfix.Int32,
	}

	i.AddDictionaryEntry(entry)

	// Now use i.Interpret() etc as usual.
}
Exemple #2
0
func ExampleInterpreter() {
	s := ipfix.NewSession()
	i := ipfix.NewInterpreter(s)

	for {
		// ParseReader will block until a full message is available.
		msg, err := s.ParseReader(os.Stdin)
		if err != nil {
			panic(err)
		}

		var fieldList []ipfix.InterpretedField
		for _, record := range msg.DataRecords {
			fieldList = i.InterpretInto(record, fieldList)
			fmt.Println(fieldList)
		}
	}
}
Exemple #3
0
func (probe *IpfixProbe) Start() error {
	var buf [4096]byte

	addr := net.UDPAddr{
		Port: probe.Port,
		IP:   net.ParseIP(probe.Addr),
	}
	conn, err := net.ListenUDP("udp", &addr)
	defer conn.Close()
	if err != nil {
		return err
	}

	s := ipfix.NewSession()
	i := ipfix.NewInterpreter(s)
	_ = i

	reader := bytes.NewReader(buf[:])
	for {
		_, _, err := conn.ReadFromUDP(buf[:])
		// ParseReader will block until a full message is available.
		msg, err := s.ParseReader(reader)
		if err != nil {
			panic(err)
		}
		reader.Seek(0, 0)
		fmt.Println("-----------------------------")
		fmt.Println(msg)
		fmt.Println("-----------------------------")

		for _, record := range msg.DataRecords {
			fmt.Println(i.Interpret(record))
			// record contains raw enterpriseId, fieldId => []byte information
			//fmt.Println(record)
		}
	}

	return nil
}