Exemplo n.º 1
0
// create a new netflow object for the specified bridge
func (b *bridge) NewNetflow(timeout int) (*gonetflow.Netflow, error) {
	nf, port, err := gonetflow.NewNetflow()
	if err != nil {
		return nil, err
	}

	// connect openvswitch to our new netflow object
	var sOut bytes.Buffer
	var sErr bytes.Buffer
	p := process("ovs")
	cmd := &exec.Cmd{
		Path: p,
		Args: []string{
			p,
			"--",
			"set",
			"Bridge",
			b.Name,
			"netflow=@nf",
			"--",
			"--id=@nf",
			"create",
			"NetFlow",
			fmt.Sprintf("targets=\"127.0.0.1:%v\"", port),
			fmt.Sprintf("active-timeout=%v", timeout),
		},
		Env:    nil,
		Dir:    "",
		Stdout: &sOut,
		Stderr: &sErr,
	}
	log.Debug("creating netflow to bridge with cmd: %v", cmd)
	ovsLock.Lock()
	err = cmdTimeout(cmd, OVS_TIMEOUT)
	ovsLock.Unlock()
	if err != nil {
		e := fmt.Errorf("NewNetflow: could not enable netflow: %v: %v", err, sErr.String())
		return nil, e
	}

	b.Lock.Lock()
	b.nf = nf
	b.Lock.Unlock()
	return nf, nil
}
Exemplo n.º 2
0
// NewNetflow creates a new netflow for the bridge.
func (b *Bridge) NewNetflow(timeout int) (*gonetflow.Netflow, error) {
	bridgeLock.Lock()
	defer bridgeLock.Unlock()

	log.Info("creating netflow on bridge %v", b.Name)

	if b.nf != nil {
		return nil, fmt.Errorf("bridge already has a netflow object")
	}

	nf, port, err := gonetflow.NewNetflow()
	if err != nil {
		return nil, err
	}

	// connect openvswitch to our new netflow object
	args := []string{
		"--",
		"set",
		"Bridge",
		b.Name,
		"netflow=@nf",
		"--",
		"--id=@nf",
		"create",
		"NetFlow",
		fmt.Sprintf("targets=\"127.0.0.1:%v\"", port),
		fmt.Sprintf("active-timeout=%v", timeout),
	}

	if _, err := ovsCmdWrapper(args); err != nil {
		return nil, fmt.Errorf("enable netflow failed: %v", err)
	}

	b.nf = nf

	return nf, nil
}