Beispiel #1
0
func TestInterfacePipeline(t *testing.T) {
	fm := NewFlowMapper()

	tenantIDExpected := "tenant-id"
	VNIExpected := uint64(1008)

	fd := &FakeInterfaceDriver{FakeTenantID: tenantIDExpected, FakeVNI: VNIExpected}
	im := NewInterfaceMapper([]InterfaceMappingDriver{fd})

	fm.SetInterfaceMapper(im)

	f := flow.New("127.0.0.1", 1, 2, nil)

	fm.Enhance([]*flow.Flow{f})
	if f.GetAttributes().GetIntfAttrSrc().GetIfIndex() != 1 || f.GetAttributes().GetIntfAttrDst().GetIfIndex() != 2 {
		t.Error("Original flow attributes ovverided")
	}
	if f.GetAttributes().GetIntfAttrSrc().GetTenantID() != tenantIDExpected || f.GetAttributes().GetIntfAttrSrc().GetVNI() != VNIExpected {
		t.Error("Flow src interface attrs not updated: ",
			f.GetAttributes().GetIntfAttrSrc(), " expected ", tenantIDExpected, ", ", VNIExpected)
	}
	if f.GetAttributes().GetIntfAttrDst().GetTenantID() != tenantIDExpected || f.GetAttributes().GetIntfAttrDst().GetVNI() != VNIExpected {
		t.Error("Flow dst interface attrs not updated: ",
			f.GetAttributes().GetIntfAttrDst(), " expected ", tenantIDExpected, ", ", VNIExpected)
	}
}
Beispiel #2
0
func TestInterfacePipelineAddingIfNameDriver(t *testing.T) {
	fm := NewFlowMapper()

	tenantIDExpected := "tenant-id"
	VNIExpected := uint64(1008)

	fd := &FakeInterfaceDriver{FakeTenantID: tenantIDExpected, FakeVNI: VNIExpected}
	im := NewInterfaceMapper([]InterfaceMappingDriver{fd})

	fm.SetInterfaceMapper(im)

	f := flow.New("127.0.0.1", 1, 2, nil)

	fm.Enhance([]*flow.Flow{f})
	if f.GetAttributes().GetIntfAttrSrc().GetIfIndex() != 1 || f.GetAttributes().GetIntfAttrDst().GetIfIndex() != 2 {
		t.Error("Original flow attributes ovverided")
	}
	if f.GetAttributes().GetIntfAttrSrc().GetTenantID() != tenantIDExpected || f.GetAttributes().GetIntfAttrSrc().GetVNI() != VNIExpected {
		t.Error("Flow src interface attrs not updated: ",
			f.GetAttributes().GetIntfAttrSrc(), " expected ", tenantIDExpected, ", ", VNIExpected)
	}
	if f.GetAttributes().GetIntfAttrDst().GetTenantID() != tenantIDExpected || f.GetAttributes().GetIntfAttrDst().GetVNI() != VNIExpected {
		t.Error("Flow dst interface attrs not updated: ",
			f.GetAttributes().GetIntfAttrDst(), " expected ", tenantIDExpected, ", ", VNIExpected)
	}

	/* add a driver that will handles the IfName attribute */
	intfExpected := "eth0"
	id := &FakeIfNameDriver{FakeIfName: intfExpected}
	im.AddDriver(id)

	/* update the previous attributes */
	tenantIDExpected = "tenant-id2"
	VNIExpected = uint64(1009)

	fd.FakeTenantID = tenantIDExpected
	fd.FakeVNI = VNIExpected

	fm.Enhance([]*flow.Flow{f})
	if f.GetAttributes().GetIntfAttrSrc().GetTenantID() != tenantIDExpected || f.GetAttributes().GetIntfAttrSrc().GetVNI() != VNIExpected {
		t.Error("Flow src interface attrs updated: ",
			f.GetAttributes().GetIntfAttrSrc(), " expected ", tenantIDExpected, ", ", VNIExpected)
	}
	if f.GetAttributes().GetIntfAttrDst().GetTenantID() != tenantIDExpected || f.GetAttributes().GetIntfAttrDst().GetVNI() != VNIExpected {
		t.Error("Flow dst interface attrs updated: ",
			f.GetAttributes().GetIntfAttrDst(), " expected ", tenantIDExpected, ", ", VNIExpected)
	}
	if f.GetAttributes().GetIntfAttrSrc().GetIfName() != intfExpected {
		t.Error("Flow src interface name not updated: ",
			f.GetAttributes().GetIntfAttrSrc().GetIfName(), " expected ", intfExpected)
	}
	if f.GetAttributes().GetIntfAttrDst().GetIfName() != intfExpected {
		t.Error("Flow src interface name not updated: ",
			f.GetAttributes().GetIntfAttrDst().GetIfName(), " expected ", intfExpected)
	}
}