@@ -359,6 +359,97 @@ TEST_F(Drec_biflow, simpleParser)
359359 free (buff);
360360}
361361
362+ // Convert only forward fields
363+ TEST_F (Drec_biflow, forwardOnly)
364+ {
365+ constexpr size_t BSIZE = 2U ;
366+ char * buff = (char *) malloc (BSIZE);
367+ uint32_t flags = FDS_CD2J_ALLOW_REALLOC | FDS_CD2J_REVERSE_SKIP;
368+ size_t buff_size = BSIZE;
369+
370+ int rc = fds_drec2json (&m_drec, flags, m_iemgr.get (), &buff, &buff_size);
371+ ASSERT_GT (rc, 0 );
372+ EXPECT_EQ (size_t (rc), strlen (buff));
373+ EXPECT_NE (buff_size, BSIZE);
374+ Config cfg = parse_string (buff, JSON, " drec2json" );
375+ EXPECT_TRUE (cfg.has_key (" iana:sourceTransportPort" ));
376+ EXPECT_TRUE (cfg.has_key (" iana:sourceIPv6Address" ));
377+ EXPECT_TRUE (cfg.has_key (" iana:destinationTransportPort" ));
378+ EXPECT_TRUE (cfg.has_key (" iana:destinationIPv6Address" ));
379+ EXPECT_TRUE (cfg.has_key (" iana:protocolIdentifier" ));
380+ EXPECT_TRUE (cfg.has_key (" iana:flowStartNanoseconds" ));
381+ EXPECT_TRUE (cfg.has_key (" iana:flowEndNanoseconds" ));
382+ EXPECT_TRUE (cfg.has_key (" iana:applicationName" ));
383+ EXPECT_TRUE (cfg.has_key (" iana:applicationDescription" ));
384+ EXPECT_TRUE (cfg.has_key (" iana:interfaceName" ));
385+ EXPECT_TRUE (cfg.has_key (" iana:octetDeltaCount" ));
386+ EXPECT_TRUE (cfg.has_key (" iana:packetDeltaCount" ));
387+
388+ EXPECT_FALSE (cfg.has_key (" iana@reverse:flowStartNanoseconds@reverse" ));
389+ EXPECT_FALSE (cfg.has_key (" iana@reverse:flowEndNanoseconds@reverse" ));
390+ EXPECT_FALSE (cfg.has_key (" iana@reverse:octetDeltaCount@reverse" ));
391+ EXPECT_FALSE (cfg.has_key (" iana@reverse:packetDeltaCount@reverse" ));
392+
393+ EXPECT_EQ ((uint64_t ) cfg[" iana:octetDeltaCount" ], VALUE_BYTES); // octetDeltaCount
394+ EXPECT_EQ ((uint64_t ) cfg[" iana:packetDeltaCount" ], VALUE_PKTS); // packetDeltaCount
395+ EXPECT_EQ ((uint64_t ) cfg[" iana:sourceTransportPort" ], VALUE_SRC_PORT); // sourceTransportPort
396+ EXPECT_EQ ( cfg[" iana:sourceIPv6Address" ], VALUE_SRC_IP6); // sourceIPv6Address
397+ EXPECT_EQ ((uint64_t ) cfg[" iana:destinationTransportPort" ], VALUE_DST_PORT); // destinationTransportPort
398+ EXPECT_EQ ( cfg[" iana:destinationIPv6Address" ], VALUE_DST_IP6); // destinationIPv6Address
399+ EXPECT_EQ ((uint64_t ) cfg[" iana:protocolIdentifier" ], VALUE_PROTO); // protocolIdentifier
400+ EXPECT_EQ ((uint64_t ) cfg[" iana:flowStartNanoseconds" ], VALUE_TS_FST); // flowStartNanoseconds
401+ EXPECT_EQ ((uint64_t ) cfg[" iana:flowEndNanoseconds" ], VALUE_TS_LST); // flowEndNanoseconds
402+ EXPECT_EQ (cfg[" iana:applicationName" ], VALUE_APP_NAME); // applicationName
403+ EXPECT_EQ (cfg[" iana:applicationDescription" ], VALUE_APP_DSC); // applicationDescription
404+ free (buff);
405+ }
406+
407+ // Convert from reverse point of view without "forward only" fields
408+ TEST_F (Drec_biflow, ReverseOnly)
409+ {
410+ constexpr size_t BSIZE = 2U ;
411+ char * buff = (char *) malloc (BSIZE);
412+ uint32_t flags = FDS_CD2J_ALLOW_REALLOC | FDS_CD2J_BIFLOW_REVERSE | FDS_CD2J_REVERSE_SKIP;
413+ size_t buff_size = BSIZE;
414+
415+ int rc = fds_drec2json (&m_drec, flags, m_iemgr.get (), &buff, &buff_size);
416+ ASSERT_GT (rc, 0 );
417+ EXPECT_EQ (size_t (rc), strlen (buff));
418+ EXPECT_NE (buff_size, BSIZE);
419+ Config cfg = parse_string (buff, JSON, " drec2json" );
420+ EXPECT_TRUE (cfg.has_key (" iana:sourceTransportPort" ));
421+ EXPECT_TRUE (cfg.has_key (" iana:sourceIPv6Address" ));
422+ EXPECT_TRUE (cfg.has_key (" iana:destinationTransportPort" ));
423+ EXPECT_TRUE (cfg.has_key (" iana:destinationIPv6Address" ));
424+ EXPECT_TRUE (cfg.has_key (" iana:protocolIdentifier" ));
425+ EXPECT_TRUE (cfg.has_key (" iana:flowStartNanoseconds" ));
426+ EXPECT_TRUE (cfg.has_key (" iana:flowEndNanoseconds" ));
427+ EXPECT_TRUE (cfg.has_key (" iana:applicationName" ));
428+ EXPECT_TRUE (cfg.has_key (" iana:applicationDescription" ));
429+ EXPECT_TRUE (cfg.has_key (" iana:interfaceName" ));
430+ EXPECT_TRUE (cfg.has_key (" iana:octetDeltaCount" ));
431+ EXPECT_TRUE (cfg.has_key (" iana:packetDeltaCount" ));
432+
433+ EXPECT_FALSE (cfg.has_key (" iana@reverse:flowStartNanoseconds@reverse" ));
434+ EXPECT_FALSE (cfg.has_key (" iana@reverse:flowEndNanoseconds@reverse" ));
435+ EXPECT_FALSE (cfg.has_key (" iana@reverse:octetDeltaCount@reverse" ));
436+ EXPECT_FALSE (cfg.has_key (" iana@reverse:packetDeltaCount@reverse" ));
437+
438+ // Source and destination fields must be swapped
439+ EXPECT_EQ ((uint64_t ) cfg[" iana:octetDeltaCount" ], VALUE_BYTES_R); // octetDeltaCount
440+ EXPECT_EQ ((uint64_t ) cfg[" iana:packetDeltaCount" ], VALUE_PKTS_R); // packetDeltaCount
441+ EXPECT_EQ ((uint64_t ) cfg[" iana:sourceTransportPort" ], VALUE_DST_PORT); // sourceTransportPort
442+ EXPECT_EQ ( cfg[" iana:sourceIPv6Address" ], VALUE_DST_IP6); // sourceIPv6Address
443+ EXPECT_EQ ((uint64_t ) cfg[" iana:destinationTransportPort" ], VALUE_SRC_PORT); // destinationTransportPort
444+ EXPECT_EQ ( cfg[" iana:destinationIPv6Address" ], VALUE_SRC_IP6); // destinationIPv6Address
445+ EXPECT_EQ ((uint64_t ) cfg[" iana:protocolIdentifier" ], VALUE_PROTO); // protocolIdentifier
446+ EXPECT_EQ ((uint64_t ) cfg[" iana:flowStartNanoseconds" ], VALUE_TS_FST_R); // flowStartNanoseconds
447+ EXPECT_EQ ((uint64_t ) cfg[" iana:flowEndNanoseconds" ], VALUE_TS_LST_R); // flowEndNanoseconds
448+ EXPECT_EQ (cfg[" iana:applicationName" ], VALUE_APP_NAME); // applicationName
449+ EXPECT_EQ (cfg[" iana:applicationDescription" ], VALUE_APP_DSC); // applicationDescription
450+ free (buff);
451+ }
452+
362453// Convert Data Record with flag FDS_CD2J_NUMERIC_ID
363454TEST_F (Drec_biflow, numID)
364455{
0 commit comments