Commit e7f928f3 authored by 's avatar

Added hack for devices with colon ":" in their name. Device name beginning...

Added hack for devices with colon ":" in their name. Device name beginning with slash (for example /dev/ntxc0:0) is considered not to be in a form "hostname:devicename" but just "devicename" and can include the colon.

Multi-core support for each single Napatech adapter:
	Added support for multiple feeds in single Napatech card. Feeds can be configured by Napatech config and then used by mapi.



git-svn-id: file:///home/svn/mapi/trunk@1526 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 94103e5d
......@@ -46,12 +46,15 @@
#include <NTCI_packetclassification.h>
#include <packetclassificationstructure.h>
#include <extendeddescriptor05.h>
#include <NTCI_cardstatus.h>
#include <cardstatusstructure.h>
typedef struct napatech_instance {
pthread_attr_t th_attr;
pthread_t th_proc;
handle_t napatechhandle;
uint32_t packetfeedhandle;
int packetfeedcreated;
uint32_t channelsBitmask;
FeedBufferInformationType1_t bufferInfo;
int eventset;
......@@ -85,8 +88,8 @@ mapidrv_get_errno(int devid,int fd)
int mapidrv_authenticate(int devid, int fd, char *vo)
{
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_authenticate"));
napatech_instance_t *i = flist_get(devlist, devid);
return mapid_authenticate(&i->mapidlib, fd, vo);
napatech_instance_t *i = flist_get(devlist, devid);
return mapid_authenticate(&i->mapidlib, fd, vo);
}
#endif
......@@ -97,40 +100,43 @@ mapidrv_apply_function (int devid,int fd, int flags, char* function, mapiFunctAr
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_apply_function; devid = %d; fd = %d; function = %s", devid, fd, function));
napatech_instance_t *i=flist_get(devlist,devid);
napatech_instance_t *i = flist_get(devlist,devid);
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_apply_function; &i = %x", (int)i));
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_apply_function; &i = %x", (int) i));
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_apply_function; &i->mapidlib = %x", (int)(&i->mapidlib)));
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_apply_function; &i->mapidlib = %x", (int) (&i->mapidlib)));
int _flags = flags;
return mapid_apply_function(&i->mapidlib, fd, function, fargs, _flags);
}
int mapidrv_add_device(const char *devname, int file,int devid, global_function_list_t *gflist,void *olstatus)
int mapidrv_add_device(const char *devname, int file, int devid, global_function_list_t *gflist, void *olstatus)
{
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_add_device"));
napatech_instance_t *i=malloc(sizeof(napatech_instance_t));
napatech_instance_t *i = malloc(sizeof(napatech_instance_t));
i->napatechhandle = NULL;
i->packetfeedhandle = 0;
i->packetfeedcreated = 0;
i->bufferInfo.bufferBaseAddress = NULL;
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_add_device; devname: %s", devname));
i->name=strdup(devname);
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_add_device; i->name: %s", i->name));
i->id=devid;
// i->dagfd=-1;
i->file=file;
// i->th_proc=0;
i->hwinfo.offline=0;
i->hwinfo.devfd=i->napatechhandle;
i->hwinfo.gflist=gflist;
i->hwinfo.pkt_drop=0;
i->offline_status = olstatus;
if(devid<0)
i->name = strdup(devname);
i->id = devid;
// i->dagfd = -1;
i->file = file;
i->th_proc = pthread_self();
if(devid >= 0)
i->hwinfo.offline = 0;
else
i->hwinfo.offline = 1;
i->hwinfo.devfd = i->napatechhandle;
i->hwinfo.gflist = gflist;
i->hwinfo.pkt_drop = 0;
i->offline_status = olstatus;
DEBUG_CMD(Debug_Message("Added device %d: %s", devid, devname));
......@@ -163,13 +169,24 @@ int mapidrv_delete_device(int devid)
}
if(i->napatechhandle != NULL) {
uint32_t feeds = 0;
if((result = NTCI_GetPacketFeedCount(i->napatechhandle, &feeds)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("napatechdrv: Error in packet feed count (%i)\n", result));
}
DEBUG_CMD(Debug_Message("napatechdrv: packet feeds: %d", feeds));
if((result = NTCI_StopPacketFeed(i->napatechhandle, i->packetfeedhandle)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_delete_device; Failed to stop packet feed! (%i)\n", result));
NTCI_CloseCard(i->napatechhandle);
return -1;
}
if((result = NTCI_DestroyPacketFeed(i->napatechhandle, i->packetfeedhandle)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_delete_device; Failed to destroy packet feed! (%i)\n", result));
if(i->packetfeedcreated) {
if((result = NTCI_DestroyPacketFeed(i->napatechhandle, i->packetfeedhandle)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_delete_device; Failed to destroy packet feed! (%i)\n", result));
}
}
NTCI_CloseCard(i->napatechhandle);
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_delete_device; Napatech device closed"));
}
......@@ -178,7 +195,6 @@ int mapidrv_delete_device(int devid)
free(i->name);
if(i->offline_status != NULL)
*(i->offline_status) = DEVICE_DELETED;
free(i);
}
......@@ -214,18 +230,18 @@ process_pkts(BufferInformationSectionType1_t* bufferInformation, napatech_instan
mhdr.caplen = descriptor->StoredLength;
mhdr.wlen = descriptor->WireLength;
// Layer 2 type. (0:EtherII, 1:LLC, 2:SNAP, 3:Novell RAW)
switch(pExtDescr->l2Type) {
case 0:
i->hwinfo.link_type = DLT_EN10MB;
break;
case 1:
case 2:
case 3:
default:
DEBUG_CMD(Debug_Message("WARNING: Unexpected Layer 2 type (%d) in Extended Packet Descriptor\n", pExtDescr->l2Type));
break;
}
// Layer 2 type. (0:EtherII, 1:LLC, 2:SNAP, 3:Novell RAW)
switch(pExtDescr->l2Type) {
case 0:
i->hwinfo.link_type = DLT_EN10MB;
break;
case 1:
case 2:
case 3:
default:
DEBUG_CMD(Debug_Message("WARNING: Unexpected Layer 2 type (%d) in Extended Packet Descriptor\n", pExtDescr->l2Type));
break;
}
// ? TODO - modify third argument to pass test_packet_read
mapid_process_pkt(&i->mapidlib, (unsigned char*)frame, frame + sizeof(PacketDescriptorType2_t) + (descriptor->ExtensionLength << 3), &mhdr);
......@@ -281,8 +297,8 @@ mapidrv_proc_loop (void *arg)
{
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_proc_loop"));
int devid = *(int *)arg;
napatech_instance_t *i=flist_get(devlist,devid);
int devid = *(int *) arg;
napatech_instance_t *i = flist_get(devlist,devid);
int err;
BufferRequestSampledType2_t request;
......@@ -373,247 +389,320 @@ mapidrv_create_flow (int devid, int fd, char **devtype)
{
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_create_flow"));
napatech_instance_t *i;
napatech_instance_t *i = flist_get(devlist, devid);
*devtype = MAPI_DEVICE_NAPATECH;
if(devid < 0) {
i->hwinfo.offline = 1;
i->hwinfo.cap_length = 1500;
i->hwinfo.link_type = DLT_EN10MB;
i->hwinfo.devtype = MAPI_DEVICE_NAPATECH;
i->hwinfo.devid = i->id;
i->hwinfo.pkts = 0;
uint32_t result=0;
DEBUG_CMD(Debug_Message("Reading from trace file: %s", i->name));
return mapid_add_flow(&i->mapidlib, fd, &i->hwinfo, NULL);
}
i->hwinfo.offline = 0;
uint32_t result = 0;
uint32_t feedPriorities[] = { 1 };
FeedConfigSampledType2_t feedConfig;
// BufferInformationSectionType6_t bufferInformation;
// FeedBufferInformationType1_t bufferInfo;
// BufferRequestSampledType2_t request;
CardHardwareCapabilitiesType1_t cardCapabilities;
uint32_t channelsBitmask=0;
CardHardwareVersionCapabilitiesType3_t data3;
if(devid < 0)
{
napatech_instance_t *inst=flist_get(devlist,devid);
*devtype=MAPI_DEVICE_NAPATECH;
inst->hwinfo.offline=1;
inst->hwinfo.cap_length=1500;
inst->hwinfo.link_type=DLT_EN10MB;
inst->hwinfo.devtype=MAPI_DEVICE_NAPATECH;
inst->hwinfo.devid=inst->id;
inst->hwinfo.pkts=0;
//Open device if it is not already open
if (i->napatechhandle == NULL) {
/* Open the correct card. */
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; Trying to open NTCI based adapter #%d\n", i->name[strlen(i->name) - 1] - '0'));
if(strstr(i->name, "xyxs") != NULL) {
/* X card series. */
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; Opening X card series."));
i->napatechhandle = NTCI_OpenCard(NTCI_CARD_TYPE_ANY, i->name[strlen(i->name) - 1] - '0');
} else if(strstr(i->name, "ntxc") != NULL) {
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; Opening ntxc card series."));
i->napatechhandle = NTCI_OpenCard(NTCI_ANY_NAPATECH_CARD_TYPE, i->name[strlen(i->name) - 3] - '0');
} else if(strstr(i->name, "ntx") != NULL) {
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; Opening ntxc card series."));
i->napatechhandle = NTCI_OpenCard(NTCI_ANY_NAPATECH_CARD_TYPE, i->name[strlen(i->name) - 1] - '0');
}
if(i->napatechhandle==NULL) {
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; Failed to open adapter.\n"));
return NTCI_ERRCODE_NO_DEVICE_OPEN; // TODO
}
DEBUG_CMD(Debug_Message("Reading from trace file: %s", inst->name));
i->hwinfo.devfd = (int) i->napatechhandle;
return mapid_add_flow(&inst->mapidlib,fd,&inst->hwinfo,NULL);
i->hwinfo.cap_length = 0;
/* TODO cap_length from hw */
if (i->hwinfo.cap_length == 0) {
DEBUG_CMD(Debug_Message("WARNING: Could not get info hardware-info, using default = 1500"));
i->hwinfo.cap_length = 1500;
}
i->hwinfo.link_type=DLT_EN10MB; // TODO
i=flist_get(devlist,devid);
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; NTCI_CardIdentification() = %d", NTCI_CardIdentification(i->napatechhandle)));
i->hwinfo.devtype=MAPI_DEVICE_NAPATECH;
i->hwinfo.devid=i->id;
i->hwinfo.pkts=0;
}
i->hwinfo.offline=0;
if(i->packetfeedhandle == NULL) {
// check if some feeds exist
uint32_t feeds = 0;
if((result = NTCI_GetPacketFeedCount(i->napatechhandle, &feeds)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("napatechdrv: Error in packet feed count (%i)\n", result));
}
DEBUG_CMD(Debug_Message("napatechdrv: packet feeds: %d", feeds));
*devtype=MAPI_DEVICE_NAPATECH;
if(!feeds) {
CardHardwareCapabilitiesType1_t cardCapabilities;
//Open device if it is not already open
if (i->napatechhandle == NULL)
{
if((result = NTCI_GetCapabilities(i->napatechhandle,
CAPID_HARDWARE,
NOT_SUB_CAPABILITIES,
STID_CARD_HARDWARE_CAPABILITIES_TYPE1,
&cardCapabilities)) != NTCI_ERRCODE_SUCCESS) {
/* Open the correct card. */
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; Trying to open NTCI based adapter #%d\n", i->name[strlen(i->name) - 1] - '0'));
if(strstr(i->name, "xyxs") != NULL) {
/* X card series. */
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; Opening X card series."));
i->napatechhandle = NTCI_OpenCard(NTCI_CARD_TYPE_ANY, i->name[strlen(i->name) - 1] - '0');
} else if(strstr(i->name, "ntx") != NULL) {
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; Opening ntxc card series."));
i->napatechhandle = NTCI_OpenCard(NTCI_ANY_NAPATECH_CARD_TYPE, i->name[strlen(i->name) - 1] - '0');
}
if(i->napatechhandle==NULL) {
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; Failed to open adapter.\n"));
return NTCI_ERRCODE_NO_DEVICE_OPEN; // TODO
}
DEBUG_CMD(Debug_Message(stderr, "Error finding adapter capabilities: %i\n", result));
}
i->hwinfo.devfd = (int)i->napatechhandle;
uint32_t channelsBitmask = 0;
channelsBitmask = cardCapabilities.totalChannelsBitmask;
i->hwinfo.cap_length=0;
/* TODO cap_length from hw */
if (i->hwinfo.cap_length==0) {
DEBUG_CMD(Debug_Message("WARNING: Could not get info hardware-info, using default = 1500"));
i->hwinfo.cap_length=1500;
}
i->hwinfo.link_type=DLT_EN10MB; // TODO
if (NTCI_CardIdentification(i->napatechhandle) == NT_CARD_TYPE) {
CardHardwareVersionCapabilitiesType3_t data3;
DEBUG_CMD(Debug_Message("mapinapatechdrv: mapidrv_create_flow; NTCI_CardIdentification() = %d", NTCI_CardIdentification(i->napatechhandle)));
/* Check if we need to use NTPL to set up feeds. */
if((result = NTCI_GetCapabilities(i->napatechhandle,
CAPID_VERSION,
NOT_SUB_CAPABILITIES,
STID_CARD_HARDWARE_VERSION_CAPABILITIES_TYPE3,
&data3)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message(stderr, "Error finding HW capabilities: %i\n", result));
}
switch (data3.AdapterCard.dwInfoType) {
case 1:
if((uint16_t) ((data3.AdapterCard.u.InfoType1.qwFpgaId >> 8) & 0xFF) == 32) {
if(system("grep \"disableMultiFeed\" /opt/napatech/config/default.cfg > /dev/null") == 0) {
if(system("grep \"#disableMultiFeed\" /opt/napatech/config/default.cfg > /dev/null") != 0) {
if(system("grep disableMultiFeed /opt/napatech/config/default.cfg | grep 0 > /dev/null") == 0) {
channelsBitmask = 0;
}
} else {
channelsBitmask = 0;
}
} else {
channelsBitmask = 0;
}
}
break;
case 2:
if((uint16_t) ((data3.AdapterCard.u.InfoType2.qwFpgaId >> 8) & 0xFF) == 32) {
if(system("grep \"disableMultiFeed\" /opt/napatech/config/default.cfg > /dev/null") == 0) {
if(system("grep \"#disableMultiFeed\" /opt/napatech/config/default.cfg > /dev/null") != 0) {
if(system("grep disableMultiFeed /opt/napatech/config/default.cfg | grep 0 > /dev/null") == 0) {
channelsBitmask = 0;
}
} else {
channelsBitmask = 0;
}
} else {
channelsBitmask = 0;
}
}
break;
default:
// DEBUG_MSG(Debug_Message("Unsupported FPGA!")); // ?
return;
}
if((result = NTCI_GetCapabilities(i->napatechhandle,
CAPID_HARDWARE,
NOT_SUB_CAPABILITIES,
STID_CARD_HARDWARE_CAPABILITIES_TYPE1,
&cardCapabilities)) != NTCI_ERRCODE_SUCCESS) {
} /* if (NTCI_CardIdentification(i->napatechhandle)==NT_CARD_TYPE) */
DEBUG_CMD(Debug_Message(stderr, "Error finding adapter capabilities: %i\n", result));
}
i->hwinfo.devtype=MAPI_DEVICE_NAPATECH;
i->hwinfo.devid=i->id;
i->hwinfo.pkts=0;
channelsBitmask = cardCapabilities.totalChannelsBitmask;
if (NTCI_CardIdentification(i->napatechhandle)==NT_CARD_TYPE) {
/* Set up the packet feed engine for a single feed.
*
* The feedPriorities array is used to assign the
* priorities of different feeds when creating multiple
* simultaneous feeds; in this example it is redundant
* as only one entry is required */
/* Check if we need to use NTPL to set up feeds. */
if((result = NTCI_GetCapabilities(i->napatechhandle,
CAPID_VERSION,
NOT_SUB_CAPABILITIES,
STID_CARD_HARDWARE_VERSION_CAPABILITIES_TYPE3,
&data3)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message(stderr, "Error finding HW capabilities: %i\n", result));
}
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_create_flow; NTCI_SetupPacketFeedEngine(%d, %d, %d)", i->napatechhandle, 1, feedPriorities[0]));
switch (data3.AdapterCard.dwInfoType) {
case 1:
if((uint16_t)((data3.AdapterCard.u.InfoType1.qwFpgaId>>8)&0xFF) == 32) {
if(system("grep \"disableMultiFeed\" /opt/napatech/config/default.cfg > /dev/null") == 0) {
if(system("grep \"#disableMultiFeed\" /opt/napatech/config/default.cfg > /dev/null") != 0) {
if(system("grep disableMultiFeed /opt/napatech/config/default.cfg | grep 0 > /dev/null") == 0) {
channelsBitmask = 0;
}
} else {
channelsBitmask = 0;
}
} else {
channelsBitmask = 0;
if((result = NTCI_SetupPacketFeedEngine(i->napatechhandle, 1, feedPriorities)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("Failed to initialise packet feed engine (%i)\n", result)); //stderr
NTCI_CloseCard(i->napatechhandle);
return -1;
}
}
break;
case 2:
if((uint16_t)((data3.AdapterCard.u.InfoType2.qwFpgaId>>8)&0xFF) == 32) {
if(system("grep \"disableMultiFeed\" /opt/napatech/config/default.cfg > /dev/null") == 0) {
if(system("grep \"#disableMultiFeed\" /opt/napatech/config/default.cfg > /dev/null") != 0) {
if(system("grep disableMultiFeed /opt/napatech/config/default.cfg | grep 0 > /dev/null") == 0) {
channelsBitmask = 0;
}
} else {
channelsBitmask = 0;
FeedConfigSampledType2_t feedConfig;
/* Create the packet feed.
*
* First, initialise the feedConfig structure */
/* provide packets in sections */
feedConfig.bufferType = BUFFER_SECTION;
/* hardware native timestamps */
feedConfig.timestampType = TIMESTAMP_PCAP_NANOTIME;
/* do not deliver corrupted packets */
//feedConfig.dropErroredPacketsFlag = 0;
/* slicing is disabled */
feedConfig.sliceLength = 0;
/* large samples are used: these better handle network
* traffic fluctuations */
feedConfig.bufferBehaviour = SMALL_REGULAR_SAMPLES;
/* Create the packet feed.
*
* PACKET_FEED_SOURCE_SAMPLED is used to specify real time
* sampling of network traffic. */
if((result = NTCI_CreatePacketFeed(i->napatechhandle,
0,
channelsBitmask,
PACKET_FEED_SOURCE_SAMPLED,
PACKET_FEED_DESTINATION_EXTERNAL,
STID_FEED_CONFIG_SAMPLED_TYPE2,
&feedConfig,
&i->packetfeedhandle)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("Failed to create a packet feed (%i)\n", result)); //stderr
NTCI_CloseCard(i->napatechhandle);
return -1;
}
i->packetfeedcreated = 1;
if(channelsBitmask == 0) {
PassFilter_t command;
command.WriteHW = TRUE;
sprintf(command.achFilterString, "Capture[Priority=0;Feed=0]=ALL");
/* TODO - preclasification ^^^ */
if((result = NTCI_PacketClassification(i->napatechhandle,
STID_PASS_FILTER,
&command)) != NTCI_ERRCODE_SUCCESS) {
FilterError_t error;
result = NTCI_PacketClassification(i->napatechhandle,
STID_GET_FILTER_ERROR,
&error);
DEBUG_CMD(Debug_Message("%s\n",error.achFilterError1)); // stderr
DEBUG_CMD(Debug_Message("%s\n",error.achFilterError2)); // stderr
DEBUG_CMD(Debug_Message("%s\n",error.achFilterError3)); // stderr
NTCI_CloseCard(i->napatechhandle);
return -1;
}
} else {
channelsBitmask = 0;
}
}
break;
default:
// DEBUG_MSG(Debug_Message("Unsupported FPGA!")); // ?
return;
}
} /* if (NTCI_CardIdentification(i->napatechhandle)==NT_CARD_TYPE) */
// i->packetfeedhandle = packetFeedHandle;
i->hwinfo.devtype=MAPI_DEVICE_NAPATECH;
i->hwinfo.devid=i->id;
i->hwinfo.pkts=0;
}
else {
FeedDescriptionType1_t feedDescription;
/* Set up the packet feed engine for a single feed.
*
* The feedPriorities array is used to assign the
* priorities of different feeds when creating multiple
* simultaneous feeds; in this example it is redundant
* as only one entry is required */
int f = i->name[strlen(i->name) - 1] - '0';
if(f < feeds) {
if((result = NTCI_GetPacketFeedDescription(i->napatechhandle,
f,
STID_FEED_DESCRIPTION_TYPE1,
&feedDescription)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_create_flow; NTCI_SetupPacketFeedEngine(%d, %d, %d)", i->napatechhandle, 1, feedPriorities[0]));
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_delete_device; Error in packet feed (%d/%d) description (%i)\n", f, feeds, result));
return -1;
}
else {
i->packetfeedhandle = feedDescription.handle;
}
}
else {
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_delete_device; No such feed! (%d > %d)\n", f, feeds));
return -1;
}
if((result = NTCI_SetupPacketFeedEngine(i->napatechhandle, 1, feedPriorities)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("Failed to initialise packet feed engine (%i)\n", result)); //stderr
NTCI_CloseCard(i->napatechhandle);
return -1;
}
if((result = NTCI_StopPacketFeed(i->napatechhandle, i->packetfeedhandle)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_delete_device; Failed to stop packet feed! (%i)\n", result));
NTCI_CloseCard(i->napatechhandle);
return -1;
}
if((result = NTCI_StartPacketFeed(i->napatechhandle, i->packetfeedhandle)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("Error while starting packet feed (%i)\n", result)); // stderr
NTCI_CloseCard(i->napatechhandle);
return -1;
}
}
/* Create the packet feed.
*
* First, initialise the feedConfig structure */
/* provide packets in sections */
feedConfig.bufferType = BUFFER_SECTION;
/* hardware native timestamps */
feedConfig.timestampType = TIMESTAMP_PCAP_NANOTIME;
/* do not deliver corrupted packets */
//feedConfig.dropErroredPacketsFlag = 1;
/* slicing is disabled */
feedConfig.sliceLength = 0;
/* large samples are used: these better handle network
* traffic fluctuations */
feedConfig.bufferBehaviour = SMALL_REGULAR_SAMPLES;
/* Create the packet feed.
*
* PACKET_FEED_SOURCE_SAMPLED is used to specify real time
* sampling of network traffic. */
if((result = NTCI_CreatePacketFeed(i->napatechhandle,
0,
channelsBitmask,
PACKET_FEED_SOURCE_SAMPLED,
PACKET_FEED_DESTINATION_EXTERNAL,
STID_FEED_CONFIG_SAMPLED_TYPE2,
&feedConfig,
&i->packetfeedhandle)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("Failed to create a packet feed (%i)\n", result)); //stderr
NTCI_CloseCard(i->napatechhandle);
return -1;
}
if(channelsBitmask == 0) {
PassFilter_t command;
command.WriteHW = TRUE;
sprintf(command.achFilterString, "Capture[Priority=0;Feed=0]=ALL");
/* TODO - preclasification ^^^ */
if((result = NTCI_PacketClassification(i->napatechhandle,
STID_PASS_FILTER,
&command)) != NTCI_ERRCODE_SUCCESS) {
FilterError_t error;
result = NTCI_PacketClassification(i->napatechhandle,
STID_GET_FILTER_ERROR,
&error);
DEBUG_CMD(Debug_Message("%s\n",error.achFilterError1)); // stderr
DEBUG_CMD(Debug_Message("%s\n",error.achFilterError2)); // stderr
DEBUG_CMD(Debug_Message("%s\n",error.achFilterError3)); // stderr
if(i->bufferInfo.bufferBaseAddress == NULL) {
if((result = NTCI_GetPacketFeedBuffers(i->napatechhandle,
i->packetfeedhandle,
STID_FEED_BUFFER_INFORMATION_TYPE1,
&i->bufferInfo)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("Unable to retrieve the location of the feed buffer.\n")); // stderr
NTCI_CloseCard(i->napatechhandle);
return -1;
}
}
// i->packetfeedhandle = packetFeedHandle;
DEBUG_CMD(Debug_Message("bufferBaseAddress: %p\n", i->bufferInfo.bufferBaseAddress)); // stderr
if((result = NTCI_StartPacketFeed(i->napatechhandle, i->packetfeedhandle)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("Error while starting packet feed (%i)\n", result)); // stderr
NTCI_CloseCard(i->napatechhandle);
return -1;
}
//Start processing thread
if (pthread_attr_init (&i->th_attr) != 0)
{
DEBUG_CMD(Debug_Message("ERROR: pthread_attr_init failed"));
return DAGDRV_PTHR_ERR; // TODO
}
/* find the location of the feed buffer where new
* data will be stored */
if((result = NTCI_GetPacketFeedBuffers(i->napatechhandle,
i->packetfeedhandle,
STID_FEED_BUFFER_INFORMATION_TYPE1,
&i->bufferInfo)) != NTCI_ERRCODE_SUCCESS) {
DEBUG_CMD(Debug_Message("Unable to retrieve the location of the feed buffer.\n")); // stderr
NTCI_CloseCard(i->napatechhandle);
return -1;
if (pthread_create(&i->th_proc, &i->th_attr, (void *) mapidrv_proc_loop, (void *) &(i->id)) != 0)
{
DEBUG_CMD(Debug_Message("ERROR: pthread_create failed"));
return DAGDRV_PTHR_ERR; // TODO
}
DEBUG_CMD(Debug_Message("th_proc: %lu", i->th_proc));
}
ChannelStatusType1_t channelStatus;
int link_speed = 0;
//Start processing thread
if (pthread_attr_init (&i->th_attr) != 0)
{
DEBUG_CMD(Debug_Message("ERROR: pthread_attr_init failed"));
return DAGDRV_PTHR_ERR; // TODO
}
NTCI_GetChannelStatus(i->napatechhandle,
0x01,
STID_CHANNEL_STATUS_TYPE1,
&channelStatus);
if (pthread_create(&i->th_proc, &i->th_attr, (void *) mapidrv_proc_loop, (void *) &(i->id)) != 0)
{
DEBUG_CMD(Debug_Message("ERROR: pthread_create failed"));
return DAGDRV_PTHR_ERR; // TODO
}
}
switch(channelStatus.actualSpeed) {
case SPEED_10MB:
link_speed = 10;
break;
case SPEED_100MB:
link_speed = 100;
break;
case SPEED_1GB:
link_speed = 1000;
break;
case SPEED_10GB:
link_speed = 10000;
break;
default:
link_speed = 0; // UNKNOWN
break;
}
DEBUG_CMD(Debug_Message("Link speed: %d (channel 0)\n", link_speed)); // TODO
DEBUG_CMD(Debug_Message("napatechdrv: mapidrv_create_flow_; i->napatechhandle: %d; i->packetfeedhandle: %d", i->napatechhandle, i->packetfeedhandle));
......@@ -628,22 +717,19 @@ mapidrv_connect (int devid,int fd)
int ret;
napatech_instance_t *i=flist_get(devlist,devid);
if(i == NULL)
return -1;
return -1;
ret=mapid_connect(&i->mapidlib,fd);
if(i->hwinfo.offline==4) {
if (pthread_attr_init (&i->th_attr) != 0)
{
DEBUG_CMD(Debug_Message("ERROR: pthread_attr_init failed"));
return NICDRV_PTHR_ERR;
}
if (pthread_create
(&i->th_proc, &i->th_attr, (void *) mapidrv_offline_proc_loop, (void *) &(i->id)) != 0)
{
DEBUG_CMD(Debug_Message("ERROR: pthread_create failed"));
return NICDRV_PTHR_ERR;
}
if(pthread_attr_init (&i->th_attr) != 0) {
DEBUG_CMD(Debug_Message("ERROR: pthread_attr_init failed"));
return NICDRV_PTHR_ERR;
}
if (pthread_create(&i->th_proc, &i->th_attr, (void *) mapidrv_offline_proc_loop, (void *) &(i->id)) != 0) {
DEBUG_CMD(Debug_Message("ERROR: pthread_create failed"));
return NICDRV_PTHR_ERR;
}
}
return ret;
}
......@@ -687,7 +773,7 @@ __attribute__ ((constructor))
devlist=malloc(sizeof(flist_t));
flist_init(devlist);