com.cisco.trex.stateful.api.lowlevel.ASTFProfile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trex-java-sdk Show documentation
Show all versions of trex-java-sdk Show documentation
Java client SDK provides an implementation for TRex RPC APIs
package com.cisco.trex.stateful.api.lowlevel;
import com.google.gson.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Java implementation for TRex python sdk ASTFProfile class */
public class ASTFProfile {
private static final Logger LOGGER = LoggerFactory.getLogger(ASTFProfile.class);
private static final String L7_PRECENT = "l7_percent";
private static final String CPS = "cps";
private ASTFGlobalInfo astfClientGlobalInfo;
private ASTFGlobalInfo astfServerGlobalInfo;
private List astfTemplateList;
private Map tgName2TgId = new LinkedHashMap<>(); // template group name ->
// template group id
private ASTFProfileCache astfProfileCache = new ASTFProfileCache(this);
/**
* construct
*
* @param defaultIpGen
* @param astfTemplateList
*/
public ASTFProfile(ASTFIpGen defaultIpGen, List astfTemplateList) {
this(defaultIpGen, null, null, astfTemplateList, null);
}
/**
* constructor
*
* @param defaultIpGen
* @param astfClientGlobalInfo
* @param astfServerGlobalInfo
* @param astfTemplateList
* @param astfCapInfoList
*/
public ASTFProfile(
ASTFIpGen defaultIpGen,
ASTFGlobalInfo astfClientGlobalInfo,
ASTFGlobalInfo astfServerGlobalInfo,
List astfTemplateList,
List astfCapInfoList) {
createASTFProfile(
defaultIpGen,
astfClientGlobalInfo,
astfServerGlobalInfo,
astfTemplateList,
astfCapInfoList,
null,
null);
}
/**
* constructor Define a ASTF profile You should give at least a template or a cap_list, maybe
* both.
*
* @param defaultIpGen ASTFIPGen
* @param astfClientGlobalInfo ASTFGlobalInfo tcp parameters to be used for client side, if
* cap_list is given. This is optional. If not specified,TCP parameters for each flow will be
* taken from its cap file.
* @param astfServerGlobalInfo Same as default_tcp_server_info for client side.
* @param astfTemplateList define a list of manual templates or one template
* @param astfCapInfoList define a list of pcap files list in case there is no templates
* @param sDelay ASTFCmdDelay :class:`trex.astf.trex_astf_profile.ASTFCmdDelay` Server delay
* command before sending response back to client. This will be applied on all cap in cap
* list, unless cap specified his own s_delay. defaults to None means no delay.
* @param udpMtu int or None MTU for udp packets, if packets exceeding the specified value they
* will be cut down from L7 in order to fit. This will be applied on all cap in cap list,
* unless cap specified his own udp_mtu. defaults to None.
*/
public ASTFProfile(
ASTFIpGen defaultIpGen,
ASTFGlobalInfo astfClientGlobalInfo,
ASTFGlobalInfo astfServerGlobalInfo,
List astfTemplateList,
List astfCapInfoList,
ASTFCmdDelay sDelay,
Integer udpMtu) {
createASTFProfile(
defaultIpGen,
astfClientGlobalInfo,
astfServerGlobalInfo,
astfTemplateList,
astfCapInfoList,
sDelay,
udpMtu);
}
/**
* constructor Define a ASTF profile You should give at least a template or a cap_list, maybe
* both.
*
* @param defaultIpGen ASTFIPGen
* @param astfClientGlobalInfo ASTFGlobalInfo tcp parameters to be used for client side, if
* cap_list is given. This is optional. If not specified,TCP parameters for each flow will be
* taken from its cap file.
* @param astfServerGlobalInfo Same as default_tcp_server_info for client side.
* @param astfTemplateList define a list of manual templates or one template
* @param astfCapInfoList define a list of pcap files list in case there is no templates
* @param sDelay ASTFCmdDelayRnd see :class:`trex.astf.trex_astf_profile.ASTFCmdDelayRnd` Server
* delay command before sending response back to client. This will be applied on all cap in
* cap list, unless cap specified his own s_delay. defaults to None means no delay.
* @param udpMtu int or None MTU for udp packets, if packets exceeding the specified value they
* will be cut down from L7 in order to fit. This will be applied on all cap in cap list,
* unless cap specified his own udp_mtu. defaults to None.
*/
public ASTFProfile(
ASTFIpGen defaultIpGen,
ASTFGlobalInfo astfClientGlobalInfo,
ASTFGlobalInfo astfServerGlobalInfo,
List astfTemplateList,
List astfCapInfoList,
ASTFCmdDelayRnd sDelay,
Integer udpMtu) {
createASTFProfile(
defaultIpGen,
astfClientGlobalInfo,
astfServerGlobalInfo,
astfTemplateList,
astfCapInfoList,
sDelay,
udpMtu);
}
private void createASTFProfile(
ASTFIpGen defaultIpGen,
ASTFGlobalInfo astfClientGlobalInfo,
ASTFGlobalInfo astfServerGlobalInfo,
List astfTemplateList,
List astfCapInfoList,
ASTFCmd sDelay,
Integer udpMtu) {
if (sDelay != null
&& !(sDelay instanceof ASTFCmdDelay)
&& !(sDelay instanceof ASTFCmdDelayRnd)) {
throw new IllegalStateException(
"bad param sDelay, it should be instanceof ASTFCmdDelayRnd or ASTFCmdDelay");
}
this.astfClientGlobalInfo = astfClientGlobalInfo;
this.astfServerGlobalInfo = astfServerGlobalInfo;
if (astfTemplateList == null && astfCapInfoList == null) {
throw new IllegalStateException(
"bad param combination,ASTFTemplate and ASTFCapInfo should not be null at the same time ");
}
if (astfTemplateList != null && !astfTemplateList.isEmpty()) {
this.astfTemplateList = astfTemplateList;
List serverPorts = new ArrayList<>();
for (ASTFTemplate template : astfTemplateList) {
addTgIdToTemplate(template);
ASTFAssociation association = template.getAstfTcpServerTemplate().getAssociation();
int port = association.getPort();
if (association.isPortOnly()) {
if (serverPorts.contains(port)) {
throw new IllegalStateException(
String.format("Two server template with port: %s", port));
} else {
serverPorts.add(port);
}
}
}
}
/** for pcap file parse scenario */
if (astfCapInfoList != null && !astfCapInfoList.isEmpty()) {
String mode = null;
List