private static String replaceTcpStartPort(
     JGroupsProtocolCfg jgroupsCfg, TransportFlags transportFlags) {
   Map<String, String> props = jgroupsCfg.getProtocol(TCP).getProperties();
   Integer startPort = threadTcpStartPort.get();
   int portRange = TCP_PORT_RANGE_PER_THREAD;
   if (transportFlags.isSiteIndexSpecified()) {
     portRange = 10;
     int maxIndex = TCP_PORT_RANGE_PER_THREAD / portRange - 1;
     if (transportFlags.siteIndex() > maxIndex) {
       throw new IllegalStateException("Currently we only support " + (maxIndex + 1) + " sites!");
     }
     startPort += transportFlags.siteIndex() * portRange;
   }
   props.put("bind_port", startPort.toString());
   // In JGroups, the port_range is inclusive
   props.put("port_range", String.valueOf(portRange - 1));
   return replaceProperties(jgroupsCfg, props, TCP);
 }
  public static String getUdpConfig(String fullTestName, TransportFlags flags) {
    JGroupsProtocolCfg jgroupsCfg = getJGroupsProtocolCfg(udpConfigurator.getProtocolStack());

    if (!flags.withFD()) removeFailureDetectionUdp(jgroupsCfg);

    if (!flags.withMerge()) removeMerge(jgroupsCfg);

    if (!flags.isSiteIndexSpecified()) {
      removeRela2(jgroupsCfg);
    }

    if (jgroupsCfg.containsProtocol(TEST_PING)) {
      if (fullTestName != null)
        return getTestPingDiscovery(fullTestName, jgroupsCfg); // Cmd line test run
    }

    return replaceMCastAddressAndPort(jgroupsCfg);
  }
  public static String getTcpConfig(String fullTestName, TransportFlags flags) {
    // With the XML already parsed, make a safe copy of the
    // protocol stack configurator and use that accordingly.
    JGroupsProtocolCfg jgroupsCfg = getJGroupsProtocolCfg(tcpConfigurator.getProtocolStack());

    if (!flags.withFD()) removeFailureDetectionTcp(jgroupsCfg);

    if (!flags.isSiteIndexSpecified()) {
      removeRela2(jgroupsCfg);
    } else {
      ProtocolConfiguration protocol = jgroupsCfg.getProtocol(RELAY2);
      protocol.getProperties().put("site", flags.siteName());
      if (flags.relayConfig() != null) // if not specified, use default
      protocol.getProperties().put("config", flags.relayConfig());
    }

    if (!flags.withMerge()) removeMerge(jgroupsCfg);

    if (jgroupsCfg.containsProtocol(TEST_PING)) {
      replaceTcpStartPort(jgroupsCfg, flags);
      if (fullTestName == null) return jgroupsCfg.toString(); // IDE run of test
      else return getTestPingDiscovery(fullTestName, jgroupsCfg); // Cmd line test run
    } else {
      return replaceMCastAddressAndPort(jgroupsCfg);
    }
  }