Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connect #585

Merged
merged 8 commits into from
Dec 1, 2020
Merged

Conversation

Bolodya1997
Copy link

@Bolodya1997 Bolodya1997 commented Nov 12, 2020

Issue

Existing connect.NewServer() chain elements provides some request, connection translation which should be different for the different cases (ex: NSMgr, interpose NSE, pass through NSE) #552.

Solution

Add translationClientFactory to extract all translation logic from the connect.NewServer(), add translation package with common translation clients translation.NewNSMgrClient()..., andtranslation.Builder to create custom ones.
Add NewCrossConnectClientFactory for the cross connect (interpose NSE, pass through NSE) cases, rework connect.

@Bolodya1997 Bolodya1997 force-pushed the fix-connect branch 3 times, most recently from 186192d to a1bd7d4 Compare November 12, 2020 09:54
pkg/tools/clientmap/refcount.go Outdated Show resolved Hide resolved
@edwarnicke
Copy link
Member

One other potentially thought here... rather than having translation factories as arguments to connect ... we could have connect store its client connection in metadata and then appropriate subsequent chain elements could handle the translation without having to complicate the connect logic with translation.

@Bolodya1997
Copy link
Author

Bolodya1997 commented Nov 19, 2020

One other potentially thought here... rather than having translation factories as arguments to connect ... we could have connect store its client connection in metadata and then appropriate subsequent chain elements could handle the translation without having to complicate the connect logic with translation.

Yep, it can be very helpful to store some additional info about the server+client connections in s single place, but we need to perform translation logic before the client chain:

connect.NewServer(
	ctx,
	client.NewClientFactory(
		name,
		// What to call onHeal
		addressof.NetworkServiceClient(adapters.NewServerToClient(rv)),
		tokenGenerator,
		// <-- all these chain elements comes after the updatepath, refresh, updatetoken...
		connectioncontextkernel.NewClient(),
		tag.NewClient(ctx, vppConn),
		// mechanisms
		memif.NewClient(vppConn, &lastSocketID),
		kernel.NewClient(vppConn),
		recvfd.NewClient(),
	),
	clientDialOptions...,
),

so if we want to perform some translation, we should do it before the client.NewClientFactory() chain. And it is actually the reason why we need to pass translationFactory to the connection server.

@Bolodya1997
Copy link
Author

One other potentially thought here... rather than having translation factories as arguments to connect ... we could have connect store its client connection in metadata and then appropriate subsequent chain elements could handle the translation without having to complicate the connect logic with translation.

There are actually 2 different approaches we can use to implement server request -> client request and client connection -> server connection translations.

Use metadata and stored serverRequest, clientConnection

endpoint := chain.NewNetworkServiceServer(
    ...
    customtranslator.NewRequestServer(), // <-- creates `clientRequest` from request/metadata, stores `request` 
                                         //     as `serverRequest` in metadata, replaces `request` with
                                         //     `clientRequest`
    connection.NewServer( // <-- already uses `clientRequest`, no need for translation
        client.NewFactory(clientChain), // <-- same
    ),
    customtranslator.NewConnectionServer(), // <-- updates `clientRequest` with `conn` (`clientConn`), stores
                                            //     it in metadata, replaces `request` with `serverRequest`
    ...
)

We can't add translation as a part of clientChain because it is processed after all default client chain elements:

rv = chain.NewNetworkServiceClient(
append(
append([]networkservice.NetworkServiceClient{
authorize.NewClient(),
updatepath.NewClient(name),
heal.NewClient(ctx, networkservice.NewMonitorConnectionClient(cc), onHeal),
refresh.NewClient(ctx),
}, additionalFunctionality...),
injectpeer.NewClient(),
updatetoken.NewClient(tokenGenerator),
networkservice.NewNetworkServiceClient(cc),
)...)

so it should be performed in server chain and so we need 2 translation elements:

  1. to translate server request before starting processing client chain
  2. to translate client connection after the client chain
    Another one thing I really don't like is that NewRequestServer, connection.NewServer and NewConnectionServer are the part of the server chain but they are processing client request.

Use translationFactory

endpoint := chain.NewNetworkServiceServer(
    ...
    connection.NewServer( // <-- uses only `request`
        translation.NewClient, // <-- is inserted before the `clientChain`, replaces `request` with
                               //     `clientRequest`, returns `serverConn` instead of `clientConn`
        client.NewFactory(clientChain), // <-- already uses `clientRequest`, no need for translation
    ),
    ...
)

Here we have only 1 chain element incapsulating all translation logic and so it is only one who is processing both server and client request. No one in the server chain knows about the client request/connection, same for the client chain and the server request/connection.

Copy link
Member

@denis-tingaikin denis-tingaikin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other things look for me over desined.
But I tihnk this PR can be merged as bug fixing.

I would suggest to solve this with something like: Create two separte client factories:

  1. For nsmgr and so on.
  2. For forwarders.

Something like

nsmgr.NewClientFactory
forwarder.NewClientFactory

pkg/networkservice/common/connect/client.go Show resolved Hide resolved
pkg/networkservice/common/connect/translation/builder.go Outdated Show resolved Hide resolved
@Bolodya1997 Bolodya1997 marked this pull request as draft November 23, 2020 15:07
@edwarnicke
Copy link
Member

Use translationFactory

endpoint := chain.NewNetworkServiceServer(
    ...
    connection.NewServer( // <-- uses only `request`
        translation.NewClient, // <-- is inserted before the `clientChain`, replaces `request` with
                               //     `clientRequest`, returns `serverConn` instead of `clientConn`
        client.NewFactory(clientChain), // <-- already uses `clientRequest`, no need for translation
    ),
    ...
)

Here we have only 1 chain element incapsulating all translation logic and so it is only one who is processing both server and client request. No one in the server chain knows about the client request/connection, same for the client chain and the server request/connection.

I like this approach very much :)

@Bolodya1997 Bolodya1997 force-pushed the fix-connect branch 2 times, most recently from 24a6093 to 24c607c Compare November 25, 2020 07:30
@Bolodya1997 Bolodya1997 marked this pull request as ready for review November 25, 2020 07:33
Copy link
Member

@denis-tingaikin denis-tingaikin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

pkg/tools/clientmap/refcount.go Outdated Show resolved Hide resolved
@Bolodya1997 Bolodya1997 force-pushed the fix-connect branch 2 times, most recently from 583c8ab to fe5ced7 Compare November 25, 2020 15:46
pkg/tools/clientmap/refcount.go Outdated Show resolved Hide resolved
@Bolodya1997 Bolodya1997 marked this pull request as draft November 27, 2020 09:28
Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>
@Bolodya1997 Bolodya1997 marked this pull request as ready for review December 1, 2020 04:11
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Vladimir Popov added 4 commits December 1, 2020 11:13
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Copy link
Member

@denis-tingaikin denis-tingaikin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bolodya1997 Could you also update vpp-forwarder and vppagent-forwarder?

@denis-tingaikin denis-tingaikin merged commit d0ca5e4 into networkservicemesh:master Dec 1, 2020
nsmbot pushed a commit to networkservicemesh/sdk-kernel that referenced this pull request Dec 1, 2020
…k@master networkservicemesh/sdk#585

networkservicemesh/sdk PR link: networkservicemesh/sdk#585

networkservicemesh/sdk commit message:
commit d0ca5e402484ded32f2b85dd94d4f283360424f8
Author: Vladimir Popov <vladimir.popov@xored.com>
Date:   Tue Dec 1 15:12:47 2020 +0700

    Fix connect (#585)

    * Added translateMechanism chain element

    Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

    * Rework connect.NewServer

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add RefcountMap.LoadUnsafe()

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Fix connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Move translation client implementations to the related places

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add new clients, rework connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Rename translation to mechanismtranslation

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Make RefcountMap.Delete() return bool

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-registry-memory that referenced this pull request Dec 1, 2020
…k@master networkservicemesh/sdk#585

networkservicemesh/sdk PR link: networkservicemesh/sdk#585

networkservicemesh/sdk commit message:
commit d0ca5e402484ded32f2b85dd94d4f283360424f8
Author: Vladimir Popov <vladimir.popov@xored.com>
Date:   Tue Dec 1 15:12:47 2020 +0700

    Fix connect (#585)

    * Added translateMechanism chain element

    Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

    * Rework connect.NewServer

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add RefcountMap.LoadUnsafe()

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Fix connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Move translation client implementations to the related places

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add new clients, rework connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Rename translation to mechanismtranslation

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Make RefcountMap.Delete() return bool

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsmgr-proxy that referenced this pull request Dec 1, 2020
…k@master networkservicemesh/sdk#585

networkservicemesh/sdk PR link: networkservicemesh/sdk#585

networkservicemesh/sdk commit message:
commit d0ca5e402484ded32f2b85dd94d4f283360424f8
Author: Vladimir Popov <vladimir.popov@xored.com>
Date:   Tue Dec 1 15:12:47 2020 +0700

    Fix connect (#585)

    * Added translateMechanism chain element

    Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

    * Rework connect.NewServer

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add RefcountMap.LoadUnsafe()

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Fix connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Move translation client implementations to the related places

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add new clients, rework connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Rename translation to mechanismtranslation

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Make RefcountMap.Delete() return bool

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nse-icmp-responder that referenced this pull request Dec 1, 2020
…k@master networkservicemesh/sdk#585

networkservicemesh/sdk PR link: networkservicemesh/sdk#585

networkservicemesh/sdk commit message:
commit d0ca5e402484ded32f2b85dd94d4f283360424f8
Author: Vladimir Popov <vladimir.popov@xored.com>
Date:   Tue Dec 1 15:12:47 2020 +0700

    Fix connect (#585)

    * Added translateMechanism chain element

    Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

    * Rework connect.NewServer

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add RefcountMap.LoadUnsafe()

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Fix connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Move translation client implementations to the related places

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add new clients, rework connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Rename translation to mechanismtranslation

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Make RefcountMap.Delete() return bool

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsmgr that referenced this pull request Dec 1, 2020
…k@master networkservicemesh/sdk#585

networkservicemesh/sdk PR link: networkservicemesh/sdk#585

networkservicemesh/sdk commit message:
commit d0ca5e402484ded32f2b85dd94d4f283360424f8
Author: Vladimir Popov <vladimir.popov@xored.com>
Date:   Tue Dec 1 15:12:47 2020 +0700

    Fix connect (#585)

    * Added translateMechanism chain element

    Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

    * Rework connect.NewServer

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add RefcountMap.LoadUnsafe()

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Fix connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Move translation client implementations to the related places

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add new clients, rework connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Rename translation to mechanismtranslation

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Make RefcountMap.Delete() return bool

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
@denis-tingaikin
Copy link
Member

@edwarnicke Let us know if you have something in mind related to this changes.

nsmbot pushed a commit to networkservicemesh/cmd-registry-proxy-dns that referenced this pull request Dec 1, 2020
…k@master networkservicemesh/sdk#585

networkservicemesh/sdk PR link: networkservicemesh/sdk#585

networkservicemesh/sdk commit message:
commit d0ca5e402484ded32f2b85dd94d4f283360424f8
Author: Vladimir Popov <vladimir.popov@xored.com>
Date:   Tue Dec 1 15:12:47 2020 +0700

    Fix connect (#585)

    * Added translateMechanism chain element

    Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

    * Rework connect.NewServer

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add RefcountMap.LoadUnsafe()

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Fix connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Move translation client implementations to the related places

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add new clients, rework connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Rename translation to mechanismtranslation

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Make RefcountMap.Delete() return bool

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/sdk-vpp that referenced this pull request Dec 1, 2020
…k@master networkservicemesh/sdk#585

networkservicemesh/sdk PR link: networkservicemesh/sdk#585

networkservicemesh/sdk commit message:
commit d0ca5e402484ded32f2b85dd94d4f283360424f8
Author: Vladimir Popov <vladimir.popov@xored.com>
Date:   Tue Dec 1 15:12:47 2020 +0700

    Fix connect (#585)

    * Added translateMechanism chain element

    Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

    * Rework connect.NewServer

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add RefcountMap.LoadUnsafe()

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Fix connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Move translation client implementations to the related places

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add new clients, rework connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Rename translation to mechanismtranslation

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Make RefcountMap.Delete() return bool

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/sdk-vppagent that referenced this pull request Dec 1, 2020
…k@master networkservicemesh/sdk#585

networkservicemesh/sdk PR link: networkservicemesh/sdk#585

networkservicemesh/sdk commit message:
commit d0ca5e402484ded32f2b85dd94d4f283360424f8
Author: Vladimir Popov <vladimir.popov@xored.com>
Date:   Tue Dec 1 15:12:47 2020 +0700

    Fix connect (#585)

    * Added translateMechanism chain element

    Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

    * Rework connect.NewServer

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add RefcountMap.LoadUnsafe()

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Fix connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Move translation client implementations to the related places

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Add new clients, rework connect

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Rename translation to mechanismtranslation

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    * Make RefcountMap.Delete() return bool

    Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

    Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
illbegood pushed a commit to illbegood/sdk that referenced this pull request Dec 20, 2020
* Added translateMechanism chain element

Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

* Rework connect.NewServer

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Add RefcountMap.LoadUnsafe()

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Fix connect

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Move translation client implementations to the related places

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Add new clients, rework connect

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Rename translation to mechanismtranslation

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Make RefcountMap.Delete() return bool

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>
Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
illbegood pushed a commit to illbegood/sdk that referenced this pull request Dec 20, 2020
* Added translateMechanism chain element

Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

* Rework connect.NewServer

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Add RefcountMap.LoadUnsafe()

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Fix connect

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Move translation client implementations to the related places

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Add new clients, rework connect

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Rename translation to mechanismtranslation

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Make RefcountMap.Delete() return bool

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>
Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
illbegood pushed a commit to illbegood/sdk that referenced this pull request Dec 23, 2020
* Added translateMechanism chain element

Signed-off-by: Tigran Manasyan <tigran.manasyan@xored.com>

* Rework connect.NewServer

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Add RefcountMap.LoadUnsafe()

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Fix connect

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Move translation client implementations to the related places

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Add new clients, rework connect

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Rename translation to mechanismtranslation

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

* Make RefcountMap.Delete() return bool

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>

Co-authored-by: Tigran Manasyan <tigran.manasyan@xored.com>
Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
@Bolodya1997 Bolodya1997 deleted the fix-connect branch January 20, 2021 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants