Exemple #1
0
func (this Link) SetHwAddr() Link {
	if this.HwAddr == "" {
		this.HwAddr = pool.ThePool().NextMac(firstrealhw().HardwareAddr.String())
	}

	return this
}
Exemple #2
0
func (this Link) SetCidr() Link {
	if this.Cidr == "" {
		this.Cidr = pool.ThePool().NextCidr()
	}

	return this
}
Exemple #3
0
func TestHostToHost(t *testing.T) {
	pool.ThePool("192.168.55.1/24")

	h1, err := NewHost()
	if err != nil {
		t.Fatal(err)
	}
	defer h1.Release()

	h2, err := NewHost()
	if err != nil {
		t.Fatal(err)
	}
	defer h2.Release()

	p := NewLink(h1, h2)

	if err := p.Create(); err != nil {
		t.Fatal(err)
	}

	p, err = p.Up()
	if err != nil {
		t.Fatal(err)
	}

	h1.AddLink(p.Left)
	h2.AddLink(p.Right)

	if err := ping(h1, h2); err != nil {
		t.Fatal("Ping failed:", err)
	}
}
Exemple #4
0
func init() {
	pool.ThePool("192.168.55.1/24")
}
func TestTopoSimple(t *testing.T) {
	root, err := NewSwitch()
	if err != nil {
		t.Fatal(err)
	}

	defer root.Release()

	hosts := []*Host{}

	pool.ThePool("192.168.55.1/24")

	for i := 0; i < 10; i++ {
		host, err := NewHost(hostname(65535))
		if err != nil {
			t.Fatal(err)
		}

		defer host.Release()

		pair := NewLink(root, host, Link{Cidr: noip})
		pair.Create()

		if err := root.AddLink(pair.Left); err != nil {
			t.Fatal(err)
		}

		if err := pair.Left.Up(); err != nil {
			t.Fatal(err)
		}

		if err := pair.Right.ApplyCidr(); err != nil {
			t.Fatal(err)
		}

		if err := pair.Right.Up(); err != nil {
			t.Fatal(err)
		}

		host.AddLink(pair.Right)

		hosts = append(hosts, host)
	}

	for _, src := range hosts {
		for _, dst := range hosts {
			if src.NodeName() == dst.NodeName() {
				continue
			}

			out, err := RunCommand("ip", "netns", "exec", src.NodeName(), "ping", "-c1", dst.Links[0].Ip())
			if err != nil {
				t.Fatal(err, out)
			}

			if !strings.Contains(out, "1 received") {
				t.Fatal("Can't reach 192.168.55.1 from", dst.Links[0].Ip(), "\n",
					"Output:", out)
			}

		}
	}

}