// TODO: we should pass a list of pfcpSessionData if we will test multiple UEs
we should pass a list of pfcpSessionData if we will test multiple UEs
// TODO : we should pass a list of pfcpSessionData if we will test multiple UEs
func verifyP4RuntimeEntries(t *testing.T, testdata *pfcpSessionData, expectedValues p4RtValues, afterModification bool) {
	p4rtClient, err := providers.ConnectP4rt("127.0.0.1:50001", ReaderElectionID)
	require.NoErrorf(t, err, "failed to connect to P4Runtime server")
	defer providers.DisconnectP4rt()
	var (
		expectedApplicationsEntries = 1
	)
	if !afterModification {
		expectedValues.tunnelPeerID = 0
	}
	expectedApplicationsEntry := buildExpectedApplicationsEntry(p4rtClient, testdata, expectedValues)
	if expectedApplicationsEntry == nil {
		expectedApplicationsEntries = 0
	}
	entries, _ := p4rtClient.ReadTableEntryWildcard("PreQosPipe.applications")
	require.Equal(t, expectedApplicationsEntries, len(entries),
		fmt.Sprintf("PreQosPipe.applications should contain %v entry", expectedApplicationsEntries))
	if len(entries) > 0 {
		require.Equal(t, expectedApplicationsEntry, entries[0], "PreQosPipe.applications does not equal expected",
			entries)
	}
	entries, _ = p4rtClient.ReadTableEntryWildcard("PreQosPipe.sessions_uplink")
	require.Equal(t, 1, len(entries),
		fmt.Sprintf("PreQosPipe.sessions_uplink should contain %v entries", 1))
	require.Equal(t, buildExpectedSessionsUplinkEntry(p4rtClient, testdata), entries[0], "PreQosPipe.sessions_uplink does not equal expected")
	entries, _ = p4rtClient.ReadTableEntryWildcard("PreQosPipe.sessions_downlink")
	require.Equal(t, 1, len(entries), "PreQosPipe.sessions_downlink should contain 1 entry")
	require.Equal(t, buildExpectedSessionsDownlinkEntry(p4rtClient, expectedValues), entries[0], "PreQosPipe.sessions_downlink does not equal expected")
	tunnelPeerSessionsDownlink := entries[0].Action.GetAction().Params[0].Value
	entries, _ = p4rtClient.ReadTableEntryWildcard("PreQosPipe.terminations_uplink")
	require.Equal(t, 1, len(entries), "PreQosPipe.terminations_uplink should contain 1 entry")
	expected := buildExpectedTerminationsUplinkEntry(p4rtClient, expectedValues)
	require.Equal(t, expected.Action.GetAction().ActionId, entries[0].Action.GetAction().ActionId, "PreQosPipe.terminations_uplink action does not equal expected")
	require.NotEqual(t, []byte{0}, entries[0].Action.GetAction().Params[0].Value)
	require.Equal(t, expected.Match, entries[0].Match, "PreQosPipe.terminations_uplink match fields do not equal expected")
	entries, _ = p4rtClient.ReadTableEntryWildcard("PreQosPipe.terminations_downlink")
	require.Equal(t, 1, len(entries), "PreQosPipe.terminations_downlink should contain 1 entry")
	expected = buildExpectedTerminationsDownlinkEntry(p4rtClient, testdata, expectedValues, afterModification)
	require.Equal(t, expected.Action.GetAction().ActionId, entries[0].Action.GetAction().ActionId, "PreQosPipe.terminations_downlink action does not equal expected")
	require.NotEqual(t, []byte{0}, entries[0].Action.GetAction().Params[0].Value)
	require.Equal(t, expected.Match, entries[0].Match, "PreQosPipe.terminations_downlink match fields do not equal expected")
	if afterModification {
		require.Equal(t, expected.Action.GetAction().Params[1], entries[0].Action.GetAction().Params[1],
			fmt.Sprintf("Action param (TEID) of action %v does not equal expected", ActDownlinkTermFwdNoTC))
		require.Equal(t, expected.Action.GetAction().Params[2], entries[0].Action.GetAction().Params[2],
			fmt.Sprintf("Action param (QFI) of action %v does not equal expected", ActDownlinkTermFwdNoTC))
	}
	if afterModification {
		entries, _ = p4rtClient.ReadTableEntryWildcard("PreQosPipe.tunnel_peers")
		require.Equal(t, 1, len(entries), "PreQosPipe.tunnel_peers should contain 1 entry")
		require.Equal(t, buildExpectedTunnelPeersEntry(p4rtClient, testdata, expectedValues.tunnelPeerID), entries[0],
			"PreQosPipe.tunnel_peers does not equal expected")
		require.Equal(t, tunnelPeerSessionsDownlink, entries[0].GetMatch()[0].GetExact().Value)
	}
}
func verifyP4RuntimeEntries ( t * testing . T , testdata * pfcpSessionData , expectedValues p4RtValues , afterModification bool ) { p4rtClient , err := providers . ConnectP4rt ( " " , ReaderElectionID ) require . NoErrorf ( t , err , " " ) defer providers . DisconnectP4rt ( ) var ( expectedApplicationsEntries = 1 ) if ! afterModification { expectedValues . tunnelPeerID = 0 } expectedApplicationsEntry := buildExpectedApplicationsEntry ( p4rtClient , testdata , expectedValues ) if expectedApplicationsEntry == nil { expectedApplicationsEntries = 0 } entries , _ := p4rtClient . ReadTableEntryWildcard ( " " ) require . Equal ( t , expectedApplicationsEntries , len ( entries ) , fmt . Sprintf ( " " , expectedApplicationsEntries ) ) if len ( entries ) > 0 { require . Equal ( t , expectedApplicationsEntry , entries [ 0 ] , " " , entries ) } entries , _ = p4rtClient . ReadTableEntryWildcard ( " " ) require . Equal ( t , 1 , len ( entries ) , fmt . Sprintf ( " " , 1 ) ) require . Equal ( t , buildExpectedSessionsUplinkEntry ( p4rtClient , testdata ) , entries [ 0 ] , " " ) entries , _ = p4rtClient . ReadTableEntryWildcard ( " " ) require . Equal ( t , 1 , len ( entries ) , " " ) require . Equal ( t , buildExpectedSessionsDownlinkEntry ( p4rtClient , expectedValues ) , entries [ 0 ] , " " ) tunnelPeerSessionsDownlink := entries [ 0 ] . Action . GetAction ( ) . Params [ 0 ] . Value entries , _ = p4rtClient . ReadTableEntryWildcard ( " " ) require . Equal ( t , 1 , len ( entries ) , " " ) expected := buildExpectedTerminationsUplinkEntry ( p4rtClient , expectedValues ) require . Equal ( t , expected . Action . GetAction ( ) . ActionId , entries [ 0 ] . Action . GetAction ( ) . ActionId , " " ) require . NotEqual ( t , [ ] byte { 0 } , entries [ 0 ] . Action . GetAction ( ) . Params [ 0 ] . Value ) require . Equal ( t , expected . Match , entries [ 0 ] . Match , " " ) entries , _ = p4rtClient . ReadTableEntryWildcard ( " " ) require . Equal ( t , 1 , len ( entries ) , " " ) expected = buildExpectedTerminationsDownlinkEntry ( p4rtClient , testdata , expectedValues , afterModification ) require . Equal ( t , expected . Action . GetAction ( ) . ActionId , entries [ 0 ] . Action . GetAction ( ) . ActionId , " " ) require . NotEqual ( t , [ ] byte { 0 } , entries [ 0 ] . Action . GetAction ( ) . Params [ 0 ] . Value ) require . Equal ( t , expected . Match , entries [ 0 ] . Match , " " ) if afterModification { require . Equal ( t , expected . Action . GetAction ( ) . Params [ 1 ] , entries [ 0 ] . Action . GetAction ( ) . Params [ 1 ] , fmt . Sprintf ( " " , ActDownlinkTermFwdNoTC ) ) require . Equal ( t , expected . Action . GetAction ( ) . Params [ 2 ] , entries [ 0 ] . Action . GetAction ( ) . Params [ 2 ] , fmt . Sprintf ( " " , ActDownlinkTermFwdNoTC ) ) } if afterModification { entries , _ = p4rtClient . ReadTableEntryWildcard ( " " ) require . Equal ( t , 1 , len ( entries ) , " " ) require . Equal ( t , buildExpectedTunnelPeersEntry ( p4rtClient , testdata , expectedValues . tunnelPeerID ) , entries [ 0 ] , " " ) require . Equal ( t , tunnelPeerSessionsDownlink , entries [ 0 ] . GetMatch ( ) [ 0 ] . GetExact ( ) . Value ) } }
we should pass a list of pfcpSessionData if we will test multiple UEs
we should pass a list of pfcpSessionData if we will test multiple UEs
// new tunnel peer // FIXME: uncomment once pfcpiface properly removes all the state, see SDFAB-960 //allInstalledEntries, _ := p4rtClient.ReadTableEntryWildcard("") //require.Equal(t, expectedNumberOfAllEntries, len(allInstalledEntries), //	fmt.Sprintf("UP4 should have exactly %v p4RtEntries installed", expectedNumberOfAllEntries), //	allInstalledEntries) // we don't compare the entire object because counter ID is auto-generated by pfcpiface // check if counter index doesn't equal 0 // we don't compare the entire object because counter ID is auto-generated by pfcpiface // check if counter index doesn't equal 0 // ignore counter ID as it is random number generated by pfcpiface // check consistency between tunnel peers and sessions downlink