Skip to content

Commit

Permalink
ipfix rename default and dest to NatEvent and FlowUsage
Browse files Browse the repository at this point in the history
  • Loading branch information
mogaika committed Feb 12, 2024
1 parent d3eccca commit 1edb4dc
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 109 deletions.
72 changes: 36 additions & 36 deletions test/e2e/ipfix_e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,33 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
})
})

ginkgo.Context("default template", func() {
ginkgo.Context("NatEvent template", func() {
v.withIPFIXHandler()

ginkgo.It("sends IPFIX reports as requested [TCP]", func() {
v.verifyIPFIX(ipfixVerifierCfg{
farTemplate: "default",
farTemplate: "NatEvent",
trafficCfg: smallVolumeHTTPConfig(nil),
protocol: layers.IPProtocolTCP,
expectedTrafficPort: 80,
})
v.verifyIPFIXDefaultRecords()
v.verifyIPFIXNatEventRecords()
})

ginkgo.It("sends IPFIX reports as requested [TCP] [proxy]", func() {
v.verifyIPFIX(ipfixVerifierCfg{
farTemplate: "default",
farTemplate: "NatEvent",
trafficCfg: smallVolumeHTTPConfig(nil),
protocol: layers.IPProtocolTCP,
expectedTrafficPort: 80,
adf: true,
})
v.verifyIPFIXDefaultRecords()
v.verifyIPFIXNatEventRecords()
})

ginkgo.It("sends IPFIX reports as requested [UDP]", func() {
v.verifyIPFIX(ipfixVerifierCfg{
farTemplate: "default",
farTemplate: "defaNatEventult",
trafficCfg: &traffic.UDPPingConfig{
// have it span at several IPFIX reports
PacketCount: 55,
Expand All @@ -84,20 +84,20 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
protocol: layers.IPProtocolUDP,
expectedTrafficPort: 12345,
})
v.verifyIPFIXDefaultRecords()
v.verifyIPFIXNatEventRecords()
})

ginkgo.It("doesn't recreate templates with different IDs unnecessarily", func() {
v.verifyIPFIX(ipfixVerifierCfg{
farTemplate: "default",
farTemplate: "NatEvent",
trafficCfg: smallVolumeHTTPConfig(nil),
protocol: layers.IPProtocolTCP,
expectedTrafficPort: 80,
})
v.verifyIPFIXDefaultRecords()
v.verifyIPFIXNatEventRecords()
ids := v.ipfixHandler.getTemplateIDs()
v.runSession(ipfixVerifierCfg{
farTemplate: "default",
farTemplate: "NatEvent",
trafficCfg: smallVolumeHTTPConfig(nil),
protocol: layers.IPProtocolTCP,
expectedTrafficPort: 80,
Expand All @@ -108,27 +108,27 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
})
})

ginkgo.Context("dest template", func() {
ginkgo.Context("FlowUsage template", func() {
v.withIPFIXHandler()

ginkgo.It("sends IPFIX reports as requested [TCP]", func() {
v.verifyIPFIX(ipfixVerifierCfg{
farTemplate: "dest",
farTemplate: "FlowUsage",
trafficCfg: smallVolumeHTTPConfig(nil),
protocol: layers.IPProtocolTCP,
expectedTrafficPort: 80,
})
v.verifyIPFIXDestRecords()
v.verifyIPFIXFlowUsageRecords()
})

ginkgo.It("sends IPFIX reports as requested [UDP]", func() {
v.verifyIPFIX(ipfixVerifierCfg{
farTemplate: "dest",
farTemplate: "FlowUsage",
trafficCfg: &traffic.UDPPingConfig{},
protocol: layers.IPProtocolUDP,
expectedTrafficPort: 12345,
})
v.verifyIPFIXDestRecords()
v.verifyIPFIXFlowUsageRecords()
})

})
Expand All @@ -150,7 +150,7 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
ginkgo.Context("FAR override", func() {
f := framework.NewDefaultFramework(mode, ipMode)
v := &ipfixVerifier{f: f}
v.withNWIIPFIXPolicy("default")
v.withNWIIPFIXPolicy("NatEvent")
// Templates 256 and 257 are expected early because IPFIX policy
// is specified per NWI
v.withIPFIXHandler()
Expand All @@ -166,41 +166,41 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
})
})

ginkgo.Context("default template", func() {
ginkgo.Context("NatEvent template", func() {
f := framework.NewDefaultFramework(mode, ipMode)
v := &ipfixVerifier{f: f}
v.withNWIIPFIXPolicy("default")
v.withNWIIPFIXPolicy("NatEvent")
// Templates 256 and 257 are expected early because IPFIX policy
// is specified per NWI
v.withIPFIXHandler()

ginkgo.It("sends IPFIX reports as requested [TCP]", func() {
v.verifyIPFIX(tcpCfg)
v.verifyIPFIXDefaultRecords()
v.verifyIPFIXNatEventRecords()
})

ginkgo.It("sends IPFIX reports as requested [UDP]", func() {
v.verifyIPFIX(udpCfg)
v.verifyIPFIXDefaultRecords()
v.verifyIPFIXNatEventRecords()
})
})

ginkgo.Context("dest template", func() {
ginkgo.Context("FlowUsage template", func() {
f := framework.NewDefaultFramework(mode, ipMode)
v := &ipfixVerifier{f: f}
v.withNWIIPFIXPolicy("dest")
v.withNWIIPFIXPolicy("FlowUsage")
// Templates 256 and 257 are expected early because IPFIX policy
// is specified per NWI
v.withIPFIXHandler()

ginkgo.It("sends IPFIX reports as requested [TCP]", func() {
v.verifyIPFIX(tcpCfg)
v.verifyIPFIXDestRecords()
v.verifyIPFIXFlowUsageRecords()
})

ginkgo.It("sends IPFIX reports as requested [UDP]", func() {
v.verifyIPFIX(udpCfg)
v.verifyIPFIXDestRecords()
v.verifyIPFIXFlowUsageRecords()
})

})
Expand All @@ -210,7 +210,7 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
ginkgo.Context("[NAT fields]", func() {
f := framework.NewDefaultFramework(mode, ipMode)
v := &ipfixVerifier{f: f}
v.withNWIIPFIXPolicy("default")
v.withNWIIPFIXPolicy("NatEvent")
v.withReportingInterval(5)
v.withIPFIXHandler()

Expand All @@ -233,7 +233,7 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
postNATSourceIPv4Address: framework.MustParseIP("144.0.0.20").To4(),
postNAPTSourceTransportPort: 10128,
})
v.verifyIPFIXDefaultRecords()
v.verifyIPFIXNatEventRecords()
v.verifyNAT()
})
})
Expand All @@ -255,7 +255,7 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
protocol: layers.IPProtocolTCP,
expectedTrafficPort: 80,
})
v.verifyIPFIXDefaultRecords()
v.verifyIPFIXNatEventRecords()
})
})

Expand All @@ -281,7 +281,7 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
f := framework.NewDefaultFramework(mode, ipMode)
v := &ipfixVerifier{f: f}
v.withForwardingPolicy("altIP")
v.withNWIIPFIXPolicy("dest")
v.withNWIIPFIXPolicy("FlowUsage")
v.withIPFIXHandler()
ginkgo.It("records forwarding policy name in VRFname", func() {
v.verifyIPFIX(ipfixVerifierCfg{
Expand All @@ -291,14 +291,14 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
forwardingPolicyID: "altIP",
expectedUplinkVRFName: "altIP",
})
v.verifyIPFIXDestRecords()
v.verifyIPFIXFlowUsageRecords()
})
})

ginkgo.Context("reporting interval", func() {
f := framework.NewDefaultFramework(mode, ipMode)
v := &ipfixVerifier{f: f}
v.withNWIIPFIXPolicy("dest")
v.withNWIIPFIXPolicy("FlowUsage")
v.withIPFIXHandler()
const INTERVAL = 3
const MIN_REPORTS_FOR_CHECK = 5
Expand All @@ -313,7 +313,7 @@ func describeIPFIX(title string, mode framework.UPGMode, ipMode framework.UPGIPM
protocol: layers.IPProtocolTCP,
expectedTrafficPort: 80,
})
v.verifyIPFIXDestRecords()
v.verifyIPFIXFlowUsageRecords()
v.verifyReportingInterval(INTERVAL)
})
})
Expand Down Expand Up @@ -441,7 +441,7 @@ func (v *ipfixVerifier) withExtraExporter() {

func (v *ipfixVerifier) withAltCollector() {
v.modifySGi(func(nwiCfg *vpp.NWIConfig) {
nwiCfg.IPFIXPolicy = "default"
nwiCfg.IPFIXPolicy = "NatEvent"
nwiCfg.GetIPFIXCollectorIP = v.getCollectorIP
})
}
Expand All @@ -467,9 +467,9 @@ func (v *ipfixVerifier) runSession(cfg ipfixVerifierCfg) {
}

if !cfg.noTemplates {
// "flow-report-process" has loop which executes every 5 seconds,
// VPP ipfix plugin has loop which executes every 5 seconds,
// only after at least once this loop iterates - new template interval will be used
const VPP_IPFIX_TEMPLATE_REACTION_TIME = 10 * time.Second
const VPP_IPFIX_TEMPLATE_REACTION_TIME = 20 * time.Second

// After session creation vpp detects that far has template id
// and should start broadcast corresponding template
Expand Down Expand Up @@ -581,7 +581,7 @@ func (v *ipfixVerifier) verifyIPFIXSharedRecords() {
gomega.Expect(dlOctets).To(gomega.Equal(*v.ms.Reports[1][0].DownlinkVolume), "downlink volume")
}

func (v *ipfixVerifier) verifyIPFIXDefaultRecords() {
func (v *ipfixVerifier) verifyIPFIXNatEventRecords() {
var clientPort uint16

for _, r := range v.recs {
Expand Down Expand Up @@ -614,7 +614,7 @@ func (v *ipfixVerifier) verifyIPFIXDefaultRecords() {
v.verifyIPFIXSharedRecords()
}

func (v *ipfixVerifier) verifyIPFIXDestRecords() {
func (v *ipfixVerifier) verifyIPFIXFlowUsageRecords() {
uplinkVRFName := "ipv4-VRF:200"
if v.f.IPMode == framework.UPGIPModeV6 {
uplinkVRFName = "ipv6-VRF:200"
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/upg_e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ var _ = ginkgo.Describe("UPG Binary API", func() {
Nwi: util.EncodeFQDN("testing"),
IP4TableID: 42000,
IP6TableID: 42001,
IpfixPolicy: []byte("default"),
IpfixPolicy: []byte("NatEvent"),
IpfixCollectorIP: ip,
IpfixReportInterval: uint32(7),
ObservationDomainID: uint32(42),
Expand All @@ -1038,7 +1038,7 @@ var _ = ginkgo.Describe("UPG Binary API", func() {
gomega.Expect(msg.IP4TableID).To(gomega.Equal(uint32(42000)))
gomega.Expect(msg.IP6TableID).To(gomega.Equal(uint32(42001)))
ipfixPolicy := string(bytes.Trim(msg.IpfixPolicy, "\x00"))
gomega.Expect(ipfixPolicy).To(gomega.Equal("default"))
gomega.Expect(ipfixPolicy).To(gomega.Equal("NatEvent"))
gomega.Expect(msg.IpfixCollectorIP.String()).To(gomega.Equal("192.168.42.1"))
gomega.Expect(msg.IpfixReportInterval).To(gomega.Equal(uint32(7)))
gomega.Expect(msg.ObservationDomainID).To(gomega.Equal(uint32(42)))
Expand All @@ -1053,7 +1053,7 @@ var _ = ginkgo.Describe("UPG Binary API", func() {
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(out).To(gomega.ContainSubstring(
"testing, ip4-table-id 42000, ip6-table-id 42001, " +
"ipfix-policy default, ipfix-collector-ip 192.168.42.1"))
"ipfix-policy NatEvent, ipfix-collector-ip 192.168.42.1"))

req.Add = 0
reply = &upf.UpfNwiAddDelReply{}
Expand Down
4 changes: 2 additions & 2 deletions upf/upf.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ typedef struct
typedef enum
{
UPF_IPFIX_POLICY_NONE,
UPF_IPFIX_POLICY_DEFAULT,
UPF_IPFIX_POLICY_DEST,
UPF_IPFIX_POLICY_NAT_EVENT,
UPF_IPFIX_POLICY_FLOW_USAGE,
UPF_IPFIX_N_POLICIES,
// used only in FAR to indicate "do not override"
UPF_IPFIX_POLICY_UNSPECIFIED = UPF_IPFIX_N_POLICIES
Expand Down
8 changes: 4 additions & 4 deletions upf/upf_ipfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,15 @@ upf_ipfix_export_entry (vlib_main_t *vm, flow_entry_t *f, u32 now, bool last)
b0->current_length = offset;
context->next_record_offset_per_worker[my_cpu_number] = offset;

vlib_increment_simple_counter (
&gtm->upf_simple_counters[UPF_IPFIX_RECORDS_SENT],
vlib_get_thread_index (), 0, 1);

ipfix_exporter_t *exp = upf_ipfix_get_exporter (context);

if (!exp)
return;

vlib_increment_simple_counter (
&gtm->upf_simple_counters[UPF_IPFIX_RECORDS_SENT],
vlib_get_thread_index (), 0, 1);

/* Time to flush the buffer? */
if (offset + context->rec_size > exp->path_mtu)
upf_ipfix_export_send (vm, b0, context, now);
Expand Down
Loading

0 comments on commit 1edb4dc

Please sign in to comment.