github.com/hyperledger-labs/bdls@v2.1.1+incompatible/integration/ports.go (about)

     1  /*
     2  Copyright IBM Corp All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package integration
     8  
     9  import (
    10  	"fmt"
    11  	"os"
    12  
    13  	"github.com/onsi/ginkgo"
    14  )
    15  
    16  // TestPortRange represents a port range
    17  type TestPortRange int
    18  
    19  const (
    20  	basePort      = 20000
    21  	portsPerNode  = 50
    22  	portsPerSuite = 10 * portsPerNode
    23  )
    24  
    25  const (
    26  	ConfigBasePort TestPortRange = basePort + portsPerSuite*iota
    27  	DiscoveryBasePort
    28  	E2EBasePort
    29  	GossipBasePort
    30  	IdemixBasePort
    31  	LedgerPort
    32  	LifecyclePort
    33  	MSPPort
    34  	NWOBasePort
    35  	PluggableBasePort
    36  	PrivateDataBasePort
    37  	RaftBasePort
    38  	SBEBasePort
    39  )
    40  
    41  // On linux, the default ephemeral port range is 32768-60999 and can be
    42  // allocated by the system for the client side of TCP connections or when
    43  // programs explicitly request one. Given linux is our default CI system,
    44  // we want to try avoid ports in that range.
    45  func (t TestPortRange) StartPortForNode() int {
    46  	const startEphemeral, endEphemeral = 32768, 60999
    47  
    48  	port := int(t) + portsPerNode*(ginkgo.GinkgoParallelNode()-1)
    49  	if port >= startEphemeral-portsPerNode && port <= endEphemeral-portsPerNode {
    50  		fmt.Fprintf(os.Stderr, "WARNING: port %d is part of the default ephemeral port range on linux", port)
    51  	}
    52  	return port
    53  }