Hi Aleksander, The session layer session lookup tables lower are used for transport connections that are terminated in vpp. They can be used to store any connection but, as you’ve already figured out, they’ve been written to work with sessions and transport connections. Moreover, session lookup functions do more than just exact session matching, i.e., if exact matching fails, they try listener matching (wildcarded source ip/port) and session rules matching (mask-match-action lookup table).
If you’re looking for speed, and what we have is too much overhead for you, one thing you could do is to reuse the session tables and then write your own, optimized lookup functions. Another option is to directly use the underlying hash table data structure, the bihash, and then build your own CRUD and lookup infrastructure around it, based on all the examples we have in vpp. ACL and NAT, to name a few, do that already. If the session lookup tables is what you were looking for, then I’d recommend: - allocating sessions/connections on the right thread pool instead of using main thread, 0, exclusively. This way you won’t need to lock the session/tcp pools if you have multiple workers - do the lookup using session_lookup_connection_wt4/6 and provide the thread on which you’re doing the lookup - I don’t understand the logic towards the end of the snippet of code you provided. I suspect that only on the “tcon0 == 0” branch you want to add the new connection to the session table, so call session_lookup_add_connection (&tc0->connection, session_handle(s0)) only on that branch. No need to do the memcpy, use &tc0->connection. Hope this helps, Florin > On Aug 24, 2018, at 2:38 AM, Aleksander Djuric <aleksander.dju...@gmail.com> > wrote: > > Hello, all > > I need to add some control functions for trasit TCP sessions. Could you > please help me to determine the correct way to implement such feature? At now > I plan to write the VPP node wich will push all of transit TCP connections > into the sessions main table in following manner: > > tcon0 = session_lookup_connection4(fib_index0, > &ip40->src_address, &ip40->dst_address, > tcp0->src_port, tcp0->dst_port, TRANSPORT_PROTO_TCP); > if (tcon0 == 0) { > // Allocate fake session and connection > pool_get (mm->sess_main->sessions[0], s0); > memset (s0, 0, sizeof (*s0)); > s0->session_index = s0 - mm->sm_main->sessions[0]; > pool_get (mm->tcp_main->connections[0], tc0); > memset (tc0, 0, sizeof (*tc0)); > tc0->connection.c_index = tc0 - mm->tcp_main->connections[0]; > tc0->connection.s_index = s0->session_index; > s0->connection_index = tc0->connection.c_index; > s0->thread_index = thread_index; > > tc0->connection.lcl_ip.ip4.as_u32 = ip40->src_address.as_u32; > tc0->connection.rmt_ip.ip4.as_u32 = ip40->dst_address.as_u32; > tc0->connection.proto = TRANSPORT_PROTO_TCP; > tc0->connection.is_ip4 = 1; > tc0->connection.fib_index = fib_index0; > tc0->connection.thread_index = thread_index; > tc0->connection.lcl_port = tcp0->src_port; > tc0->connection.rmt_port = tcp0->dst_port; > tcon0 = &_tcon0; > clib_memcpy (tcon0, &tc0->connection, sizeof (*tcon0)); > } else { > tc0 = tcp_get_connection_from_transport(tcon0); > s0 = session_get(tcon0->s_index, thread_index); > } > session_lookup_add_connection (tcon0, session_handle(s0)); > > Is this the correct way? > > Thank you in advance, > Aleksander > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > > View/Reply Online (#10278): https://lists.fd.io/g/vpp-dev/message/10278 > Mute This Topic: https://lists.fd.io/mt/24943132/675152 > Group Owner: vpp-dev+ow...@lists.fd.io > Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub [fcoras.li...@gmail.com] > -=-=-=-=-=-=-=-=-=-=-=-
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#10279): https://lists.fd.io/g/vpp-dev/message/10279 Mute This Topic: https://lists.fd.io/mt/24943132/21656 Group Owner: vpp-dev+ow...@lists.fd.io Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-