コード例 #1
0
ファイル: client_oam_dump.c プロジェクト: rizard/ofdpa-2.0
int main(int argc, char *argv[])
{
  OFDPA_ERROR_t rc;
  char client_name[] = "ofdpa oam dump client";

  rc = ofdpaClientInitialize(client_name);
  if (rc != OFDPA_E_NONE)
  {
    printf("Error from ofdpaClientInitialize(). (rc == %d)", rc);
    return rc;
  }

  printf("--- MEG Table ---\n");
  displayMegEntries();
  printf("--- MEP Table ---\n");
  displayMepEntries();
  printf("--- MLP Group Table ---\n");
  displayMlpGroupEntries();

  return 0;
}
コード例 #2
0
int main(int argc, char *argv[])
{
  OFDPA_ERROR_t rc;
  char client_name[] = "ofdpa tunnel_dump client";

  rc = ofdpaClientInitialize(client_name);
  if (rc != OFDPA_E_NONE)
  {
    printf("Error from ofdpaClientInitialize(). (rc == %d)", rc);
    return rc;
  }

  printf("--- Tunnel Tenant Table ---\n");
  displayTenantEntries();
  printf("--- Tunnel Port Table ---\n");
  displayTunnelPortEntries();
  printf("--- Tunnel Next Hop Table ---\n");
  displayNextHopEntries();
  printf("--- Tunnel ECMP Next Hop Table ---\n");
  displayEcmpNextHopEntries();

  return 0;
}
コード例 #3
0
ファイル: client_cfg_purge.c プロジェクト: bharbhi/of-dpa
int main(int argc, char *argv[])
{
  char              client_name[] = "ofdpa purge client";
  OFDPA_ERROR_t rc;
  uint32_t count;

  ofdpaFlowEntry_t flow;
  ofdpaFlowEntryStats_t flowStats;
  uint32_t tableIdIndex;
  OFDPA_FLOW_TABLE_ID_t flowTablePurgeOrderList[] = {OFDPA_FLOW_TABLE_ID_VLAN,
                                                     OFDPA_FLOW_TABLE_ID_TERMINATION_MAC,
                                                     OFDPA_FLOW_TABLE_ID_UNICAST_ROUTING,
                                                     OFDPA_FLOW_TABLE_ID_MULTICAST_ROUTING,
                                                     OFDPA_FLOW_TABLE_ID_BRIDGING,
                                                     OFDPA_FLOW_TABLE_ID_ACL_POLICY,
                                                     OFDPA_FLOW_TABLE_ID_INGRESS_PORT};
#define FLOW_TABLE_PURGE_LIST_NUM_ENTRIES  (sizeof(flowTablePurgeOrderList)/sizeof(OFDPA_FLOW_TABLE_ID_t))
  ofdpaGroupEntry_t group;
  uint32_t tunnelPortId;
  uint32_t ecmpNextHopId;
  uint32_t nextHopId;
  uint32_t tunnelId;
  ofdpaPortEvent_t portEventData;

  rc = ofdpaClientInitialize(client_name);
  if (rc != OFDPA_E_NONE)
  {
    printf("\nFailure calling ofdpaClientInitialize(). rc = %d", rc);
    return rc;
  }

  printf("Purging flow tables.\n");
  for (tableIdIndex = 0; tableIdIndex < FLOW_TABLE_PURGE_LIST_NUM_ENTRIES; tableIdIndex++)
  {
    ofdpaFlowEntryInit(flowTablePurgeOrderList[tableIdIndex], &flow);
    count = 0;
    if ((ofdpaFlowStatsGet(&flow, &flowStats) == OFDPA_E_NONE) ||
        (ofdpaFlowNextGet(&flow, &flow) == OFDPA_E_NONE))
    {
      do
      {
        if ((rc = ofdpaFlowDelete(&flow)) == OFDPA_E_NONE)
        {
          count++;
        }
        else
        {
          printf("\tError returned from odpaFlowDelete: rc = %d, tableId = %d\n",
                 rc, flow.tableId);
        }
      } while (ofdpaFlowNextGet(&flow, &flow) == OFDPA_E_NONE);
    }

    if (count != 0)
    {
      printf("\tDeleted %d flows from tableId %d\n", count, flow.tableId);
    }
    else
    {
      printf("\tNo entries found in tableId %d\n", flow.tableId);
    }
  }

  printf("Purging group table.\n");
  memset(&group, 0, sizeof(group));
  count = 0;
  while (ofdpaGroupNextGet(group.groupId, &group) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaGroupDelete(group.groupId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaGroupDelete: rc = %d, groupId = 0x%08x\n",
             rc, group.groupId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d groups.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging logical tunnel port to tenant associations.\n");
  tunnelPortId = 0;
  ofdpaPortTypeSet(&tunnelPortId, OFDPA_PORT_TYPE_LOGICAL_TUNNEL);
  while (ofdpaTunnelPortNextGet(tunnelPortId, &tunnelPortId) == OFDPA_E_NONE)
  {
    count = 0;
    tunnelId = 0;
    while (ofdpaTunnelPortTenantNextGet(tunnelPortId, tunnelId, &tunnelId) == OFDPA_E_NONE)
    {
      if ((rc = ofdpaTunnelPortTenantDelete(tunnelPortId, tunnelId)) == OFDPA_E_NONE)
      {
        count++;
      }
      else
      {
        printf("\tError returned from ofdpaTunnelPortTenantDelete: rc = %d, tunnelPortId = 0x%08x, tunnelId = %d\n",
               rc, tunnelPortId, tunnelId);
      }
    }
    if (count != 0)
    {
      printf("\tDeleted %d tunnel logical port to tenant associations for port 0x%08x.\n", count, tunnelPortId);
    }
    else
    {
      printf("\tNo entries found for port 0x%08x.\n", tunnelPortId);
    }
  }

  printf("Purging logical tunnel ports.\n");
  tunnelPortId = 0;
  ofdpaPortTypeSet(&tunnelPortId, OFDPA_PORT_TYPE_LOGICAL_TUNNEL);
  count = 0;
  while (ofdpaTunnelPortNextGet(tunnelPortId, &tunnelPortId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaTunnelPortDelete(tunnelPortId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaTunnelPortDelete: rc = %d, tunnelPortId = 0x%08x\n",
             rc, tunnelPortId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d tunnel logical ports.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging tunnel ECMP next hop groups.\n");
  ecmpNextHopId = 0;
  count = 0;
  while (ofdpaTunnelEcmpNextHopGroupNextGet(ecmpNextHopId, &ecmpNextHopId) == OFDPA_E_NONE)
  {
    /* remove any member next hops from this group */
    nextHopId = 0;
    while ((rc = ofdpaTunnelEcmpNextHopGroupMemberNextGet(ecmpNextHopId, nextHopId, &nextHopId)) == OFDPA_E_NONE)
    {
      if ((rc = ofdpaTunnelEcmpNextHopGroupMemberDelete(ecmpNextHopId, nextHopId)) != OFDPA_E_NONE)
      {
        printf("\tError returned from ofdpaTunnelEcmpNextHopGroupMemberDelete: rc = %d, ecmpNextHopId = %d, nextHopId = %d\n",
               rc, ecmpNextHopId, nextHopId);
      }
    }

    if ((rc = ofdpaTunnelEcmpNextHopGroupDelete(ecmpNextHopId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaTunnelEcmpNextHopGroupDelete: rc = %d, nextHopId = 0x%08x\n",
             rc, nextHopId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d ECMP next hop groups.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging tenants.\n");
  tunnelId = 0;
  count = 0;
  while (ofdpaTunnelTenantNextGet(tunnelId, &tunnelId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaTunnelTenantDelete(tunnelId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaTunnelTenantDelete: rc = %d, tunnelId = %d\n",
             rc, tunnelId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d tenants.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging tunnel next hops.\n");
  nextHopId = 0;
  count = 0;
  while (ofdpaTunnelNextHopNextGet(nextHopId, &nextHopId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaTunnelNextHopDelete(nextHopId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaTunnelNextHopDelete: rc = %d, nextHopId = %d\n",
             rc, nextHopId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d next hops.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  /* retrieve all port events to allow logical ports to actually be deleted from database */
  memset(&portEventData, 0, sizeof(portEventData));
  count = 0;
  while (ofdpaPortEventNextGet(&portEventData) == OFDPA_E_NONE)
  {
    if (portEventData.eventMask & OFDPA_EVENT_PORT_DELETE)
    {
      count++;
    }
  }
  if (count != 0)
  {
    printf("\tRetrieved %d port delete events.\n", count);
  }

  return(0);
}
コード例 #4
0
int main(int argc, char *argv[])
{
  int i, j, entriesPrinted, totalPrinted, remainingCount;
  int rc;
  char client_name[] = "ofdpa flowtable_dump client";
  char docBuffer[1000];
  char argsDocBuffer[300];

  /* Our argp parser. */
  struct argp argp =
  {
    .args_doc = argsDocBuffer,
    .doc      = docBuffer,
    .options  = options,
    .parser   = parse_opt,
  };

  count = DEFAULT_COUNT;

  strcpy(argsDocBuffer, "[table_ID]");

  strcpy(docBuffer, "Prints entries in the OF-DPA flow tables. Specify table ID to print content of a single table. "
         "If no argument given, content of all tables are printed.\vDefault values:\n");
  i = strlen(docBuffer);
  i += sprintf(&docBuffer[i], "COUNT     = %d\n", DEFAULT_COUNT);
  i += sprintf(&docBuffer[i], "\n");

  rc = ofdpaClientInitialize(client_name);
  if (rc != OFDPA_E_NONE)
  {
    return rc;
  }

  /* Parse our arguments; every option seen by `parse_opt' will be reflected in
     `arguments'. */
  argp_parse(&argp, argc, argv, 0, 0, 0);

  if (showValidTableIds)
  {
    printf("Valid flow table IDs:\r\n");
    for (j = 0; j < 256; j++)
    {
      if (ofdpaFlowTableSupported(j) == OFDPA_E_NONE)
      {
        printf("  %d - %s\r\n", j, ofdpaFlowTableNameGet(j));
      }
    }
    printf("\r\n");
    return 0;
  }

  totalPrinted = 0;

  if (tableIdSpecified)
  {
    dumpFlowTable(tableId, count, &totalPrinted);
  }
  else
  {
    remainingCount = count;

    for (j = 0; j < 256; j++)
    {
      if (ofdpaFlowTableSupported(j) == OFDPA_E_NONE)
      {
        entriesPrinted = 0;

        dumpFlowTable(j, remainingCount, &entriesPrinted);

        totalPrinted += entriesPrinted;

        if (count != 0)
        {
          if (remainingCount > entriesPrinted)
          {
            remainingCount -= entriesPrinted;
          }
          else
          {
            /* printed the requested number of total entries */
            break;
          }
        }
      }
    }
  }

  /* 
   * if not printing empty table stats and no flow entries found, we haven't printed anything at all
   * so print a message letting the user know we are responsive
   */
  if ((showEmptyTables == 0) && (totalPrinted == 0))
  {
    printf("No flow entries found.\r\n");
  }
  return 0;
}
コード例 #5
0
int main(int argc, char *argv[])
{
  char              client_name[] = "ofdpa purge client";
  OFDPA_ERROR_t rc;
  uint32_t count;
  uint32_t atLeastOneGroupEntryDeleted;

  uint32_t tableId;
  ofdpaGroupEntry_t group;
  uint32_t tunnelPortId;
  uint32_t ecmpNextHopId;
  uint32_t nextHopId;
  uint32_t tunnelId;
  uint32_t megIndex;
  uint32_t lmepId;
  uint32_t localMpId;
  uint32_t rmpId;
  uint32_t mlpIndex;
  ofdpaPortEvent_t portEventData;
  ofdpaRemarkActionEntry_t remarkEntry;
  ofdpaDropStatusEntry_t dropEntry;
  ofdpaMplsQosEntry_t mplsQosEntry;
  uint32_t meterId;


  rc = ofdpaClientInitialize(client_name);
  if (rc != OFDPA_E_NONE)
  {
    printf("\nFailure calling ofdpaClientInitialize(). rc = %d", rc);
    return rc;
  }

  printf("Purging flow tables.\n");
  /* flow tables purged in phases to manage cross dependencies -
     egress flows first, then ingress flows except Ingress Port, last Ingress Port Flow table */
  for (tableId = OFDPA_FLOW_TABLE_ID_EGRESS_VLAN; tableId < 256; tableId++)
  {
    flowTablePurge(tableId);
  }
  for (tableId = (OFDPA_FLOW_TABLE_ID_INGRESS_PORT + 1); tableId < OFDPA_FLOW_TABLE_ID_EGRESS_VLAN; tableId++)
  {
    flowTablePurge(tableId);
  }
  flowTablePurge(OFDPA_FLOW_TABLE_ID_INGRESS_PORT);

  printf("Purging logical tunnel port to tenant associations.\n");
  tunnelPortId = 0;
  ofdpaPortTypeSet(&tunnelPortId, OFDPA_PORT_TYPE_LOGICAL_TUNNEL);
  while (ofdpaTunnelPortNextGet(tunnelPortId, &tunnelPortId) == OFDPA_E_NONE)
  {
    count = 0;
    tunnelId = 0;
    while (ofdpaTunnelPortTenantNextGet(tunnelPortId, tunnelId, &tunnelId) == OFDPA_E_NONE)
    {
      if ((rc = ofdpaTunnelPortTenantDelete(tunnelPortId, tunnelId)) == OFDPA_E_NONE)
      {
        count++;
      }
      else
      {
        printf("\tError returned from ofdpaTunnelPortTenantDelete: rc = %d, tunnelPortId = 0x%08x, tunnelId = %d\n",
               rc, tunnelPortId, tunnelId);
      }
    }
    if (count != 0)
    {
      printf("\tDeleted %d tunnel logical port to tenant associations for port 0x%08x.\n", count, tunnelPortId);
    }
    else
    {
      printf("\tNo entries found for port 0x%08x.\n", tunnelPortId);
    }
  }

  printf("Purging logical tunnel ports.\n");
  tunnelPortId = 0;
  ofdpaPortTypeSet(&tunnelPortId, OFDPA_PORT_TYPE_LOGICAL_TUNNEL);
  count = 0;
  while (ofdpaTunnelPortNextGet(tunnelPortId, &tunnelPortId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaTunnelPortDelete(tunnelPortId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaTunnelPortDelete: rc = %d, tunnelPortId = 0x%08x\n",
             rc, tunnelPortId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d tunnel logical ports.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging tunnel ECMP next hop groups.\n");
  ecmpNextHopId = 0;
  count = 0;
  while (ofdpaTunnelEcmpNextHopGroupNextGet(ecmpNextHopId, &ecmpNextHopId) == OFDPA_E_NONE)
  {
    /* remove any member next hops from this group */
    nextHopId = 0;
    while ((rc = ofdpaTunnelEcmpNextHopGroupMemberNextGet(ecmpNextHopId, nextHopId, &nextHopId)) == OFDPA_E_NONE)
    {
      if ((rc = ofdpaTunnelEcmpNextHopGroupMemberDelete(ecmpNextHopId, nextHopId)) != OFDPA_E_NONE)
      {
        printf("\tError returned from ofdpaTunnelEcmpNextHopGroupMemberDelete: rc = %d, ecmpNextHopId = %d, nextHopId = %d\n",
               rc, ecmpNextHopId, nextHopId);
      }
    }

    if ((rc = ofdpaTunnelEcmpNextHopGroupDelete(ecmpNextHopId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaTunnelEcmpNextHopGroupDelete: rc = %d, nextHopId = 0x%08x\n",
             rc, nextHopId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d ECMP next hop groups.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging tenants.\n");
  tunnelId = 0;
  count = 0;
  while (ofdpaTunnelTenantNextGet(tunnelId, &tunnelId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaTunnelTenantDelete(tunnelId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaTunnelTenantDelete: rc = %d, tunnelId = %d\n",
             rc, tunnelId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d tenants.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging tunnel next hops.\n");
  nextHopId = 0;
  count = 0;
  while (ofdpaTunnelNextHopNextGet(nextHopId, &nextHopId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaTunnelNextHopDelete(nextHopId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaTunnelNextHopDelete: rc = %d, nextHopId = %d\n",
             rc, nextHopId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d next hops.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging OAM Remote MP table.\n");
  rmpId = 0;
  count = 0;
  while (ofdpaOamRemoteMpNextGet(rmpId, &rmpId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaOamRemoteMpDelete(rmpId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaOamRemoteMpDelete: rc = %d, rmpId = %d\n",
             rc, rmpId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d Remote MP entries.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging MLP Group table.\n");
  mlpIndex = 0;
  count = 0;
  while (ofdpaOamMLPGroupNextGet(mlpIndex, &mlpIndex) == OFDPA_E_NONE)
  {
    lmepId = 0;
    while (ofdpaOamMepProtectionNextGet(mlpIndex, lmepId, &lmepId) == OFDPA_E_NONE)
    {
      if ((rc = ofdpaOamMepProtectionRemove(mlpIndex, lmepId)) != OFDPA_E_NONE)
      {
        printf("\tError returned from ofdpaOamMepProtectionRemove: rc = %d, mlpIndex = %d, lmepId = %d\n",
               rc, mlpIndex, lmepId);
      }
    }

    if ((rc = ofdpaOamMLPGroupDelete(mlpIndex)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaOamMLPGroupDelete: rc = %d, mlpIndex = %d\n",
             rc, mlpIndex);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d MLP Group entries.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging OAM MEP table.\n");
  lmepId = 0;
  count = 0;
  while (ofdpaOamMepNextGet(lmepId, &lmepId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaOamMepDelete(lmepId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaOamMepDelete: rc = %d, lmepId = %d\n",
             rc, lmepId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d MEP entries.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging OAM MIP table.\n");
  localMpId = 0;
  count = 0;
  while (ofdpaOamMipNextGet(localMpId, &localMpId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaOamMipDelete(localMpId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaOamMipDelete: rc = %d, localMpId = %d\n",
             rc, localMpId);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d MIP entries.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging OAM MEG table.\n");
  megIndex = 0;
  count = 0;
  while (ofdpaOamMegNextGet(megIndex, &megIndex) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaOamMegDelete(megIndex)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaOamMegDelete: rc = %d, megIndex = %d\n",
             rc, megIndex);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d MEG entries.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging Remark table.\n");
  memset(&remarkEntry, 0, sizeof(remarkEntry));
  count = 0;
  while (ofdpaRemarkEntryNextGet(&remarkEntry, &remarkEntry) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaRemarkActionDelete(&remarkEntry)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaRemarkActionDelete: rc = %d\n", rc);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d Remark entries.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging Drop Status table.\n");
  memset(&dropEntry, 0, sizeof(dropEntry));
  count = 0;
  while (ofdpaDropStatusNextGet(0, &dropEntry) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaDropStatusDelete(dropEntry.lmepId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaDropStatusDelete: rc = %d\n", rc);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d Drop entries.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging MPLS QoS table.\n");
  memset(&mplsQosEntry, 0, sizeof(mplsQosEntry));
  count = 0;
  while (ofdpaMplsQosEntryNextGet(&mplsQosEntry, &mplsQosEntry) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaMplsQosActionDelete(&mplsQosEntry)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaMplsQosActionDelete: rc = %d\n", rc);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d MPLS QoS entries.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging Meter table.\n");
  meterId = 0;
  count = 0;
  while (ofdpaMeterNextGet(meterId, &meterId) == OFDPA_E_NONE)
  {
    if ((rc = ofdpaMeterDelete(meterId)) == OFDPA_E_NONE)
    {
      count++;
    }
    else
    {
      printf("\tError returned from ofdpaMeterDelete: rc = %d\n", rc);
    }
  }
  if (count != 0)
  {
    printf("\tDeleted %d Meter entries.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  printf("Purging group table.\n");
  count = 0;

  do
  {
    memset(&group, 0, sizeof(group));
    atLeastOneGroupEntryDeleted = 0;

    while (ofdpaGroupNextGet(group.groupId, &group) == OFDPA_E_NONE)
    {
      if ((rc = ofdpaGroupDelete(group.groupId)) == OFDPA_E_NONE)
      {
        count++;
        atLeastOneGroupEntryDeleted = 1;
      }
    }
  } while (atLeastOneGroupEntryDeleted == 1);

  if (count != 0)
  {
    printf("\tDeleted %d groups.\n", count);
  }
  else
  {
    printf("\tNo entries found\n");
  }

  /* retrieve all port events to allow logical ports to actually be deleted from database */
  printf("Retrieving pending logical port delete events.\n");
  memset(&portEventData, 0, sizeof(portEventData));
  count = 0;
  while (ofdpaPortEventNextGet(&portEventData) == OFDPA_E_NONE)
  {
    if (portEventData.eventMask & OFDPA_EVENT_PORT_DELETE)
    {
      count++;
    }
  }
  if (count != 0)
  {
    printf("\tRetrieved %d port delete events.\n", count);
  }
  else
  {
    printf("\tNo events found\n");
  }

  return(0);
}
コード例 #6
0
ファイル: client_pkt_txrx.c プロジェクト: rizard/ofdpa-2.0
/* Arguments as follows:
 * argv[1] - how long to block on receive, in seconds. -1 to block forever.
 * argv[2] - port number. When 3rd arg is 0, this is the port to send on  .
 *           When 3rd arg is 1, this is the port to pretend the packet was received on.
 * argv[3] - non-zero value indicates packet is submitted to the pipeline rather than .
 *           being transmitted directly on a port.
 */
int main(int argc, char *argv[])
{
  int rc;
  char client_name[20] = "ofdpa client";

#if 0
  /* This stuff can be used to build an ARP Request packet to transmit */
  char buf[255];
  char destMac[6] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
  char srcMac[6] = { 0x00, 0xC0, 0x9F, 0xA1, 0xA2, 0xA7 };
  uint32_t targetIp = htonl(0xac010101);
  uint32_t srcIp = htonl(0xac010102);
  uint16_t etherType = htons(0x0806);
  uint16_t dot1qType = htons(0x8100);
  uint16_t vlanId = htons(0xa);
  uint16_t hwType = htons(0x1);
  uint16_t pType = htons(0x0800);
  uint16_t op = htons(0x1);
#endif
  int32_t wait;
  uint32_t portNum;
  uint32_t pipeline;
  OFDPA_ERROR_t err;
  ofdpa_buffdesc pkt;

  uint32_t maxPktSize;
  ofdpaPacket_t rxPkt;
  uint32_t i;
  struct timeval timeout;
  struct timeval *tv = NULL;

  if (argc != 4)
  {
    printf("\r\nUsage client_pkt_txrx <wait> <port> <pipeline>");
    printf("\r\n wait - how long to block on receive, in seconds. -1 to block forever");
    printf("\r\n port - port number. When <pipeline> is 0, this is the port to send on.\n"
               "        When pipeline is 1, this is the port to pretend the packet was received on.");
    printf("\r\n pipeline - non-zero value indicates packet is submitted to the pipeline rather than\n"
               "            being transmitted directly on a port.\n");
    exit(1);
  }

  rc = ofdpaClientInitialize(client_name);
  if (rc != OFDPA_E_NONE)
  {
    return rc;
  }

  rc = ofdpaClientPktSockBind();
  if (rc != OFDPA_E_NONE)
  {
    return rc;
  }

  wait = atoi(argv[1]);
  portNum = atoi(argv[2]);
  pipeline = atoi(argv[3]);

  /* Avoid compiler warnings */
  wait = wait;
  portNum = portNum;
  pipeline = pipeline;

#if 0
  /* Ethernet - tagged */
  memset(buf, 0, 255);
  memcpy(buf, destMac, 6);
  memcpy(&buf[6], srcMac, 6);
  /* 802.1q */
  memcpy(&buf[12], &dot1qType, 2);
  memcpy(&buf[14], &vlanId, 2);
  memcpy(&buf[16], &etherType, 2);

  /* ARP */
  memcpy(&buf[18], &hwType, 2);
  memcpy(&buf[20], &pType, 2);
  buf[22] = 6;
  buf[23] = 4;
  memcpy(&buf[24], &op, 2);
  memcpy(&buf[26], srcMac, 6);
  memcpy(&buf[32], &srcIp, 4);
  memcpy(&buf[42], &targetIp, 4);
  /* No need to put FCS trailer on frame */

  pkt.pstart = buf;
  pkt.size = 100;          /* No need to pad */

  if (pipeline)
  {
    /* Send through pipeline */
    err = ofdpaPktSend(&pkt, OFDPA_PKT_LOOKUP, 0, portNum);
    if (err != OFDPA_E_NONE)
    {
      printf("\nTagged packet send through pipeline failed with error %d\r\n", err);
    }
  }
  else
  {
    err = ofdpaPktSend(&pkt, 0, portNum, 0);
    if (err != OFDPA_E_NONE)
    {
      printf("\nTagged packet send failed with error %d\r\n", err);
    }
  }

#endif

  /* Wait for received packets */
  if (wait >= 0)
  {
    timeout.tv_sec = wait;
    timeout.tv_usec = 0;
    tv = &timeout;
  }

  /* Determine how large receive buffer must be */
  if (ofdpaMaxPktSizeGet(&maxPktSize) != OFDPA_E_NONE)
  {
    printf("\nFailed to determine maximum receive packet size.\r\n");
    exit(-1);
  }

  memset(&rxPkt, 0, sizeof(ofdpaPacket_t));
  rxPkt.pktData.pstart = (char*) malloc(maxPktSize);
  if (rxPkt.pktData.pstart == NULL)
  {
    printf("\nFailed to allocate receive packet buffer\r\n");
    exit(-1);
  }
  rxPkt.pktData.size = maxPktSize;

  rc = ofdpaPktReceive(tv, &rxPkt);
  while (rc == OFDPA_E_NONE)
  {
    printf("\nClient received packet");
    printf("\n Reason:  %d", rxPkt.reason);
    printf("\n Table ID:  %d", rxPkt.tableId);
    printf("\n Ingress port:  %u", rxPkt.inPortNum);
    printf("\n Size:  %u\r\n", rxPkt.pktData.size);
    for (i = 0; i < rxPkt.pktData.size; i++)
    {
      if (i && ((i % 16) == 0))
        printf("\r\n");
      printf("%02x ", (unsigned int) *(rxPkt.pktData.pstart + i));
    }
    printf("\r\n");

    /* Now resubmit the packet to the pipeline */
    pkt.size = rxPkt.pktData.size - 4;         /* Don't include FCS */
    pkt.pstart = rxPkt.pktData.pstart;
    /* Fiddle with one byte so we can tell the packet is one we sent from
     * CPU vs just being forwarded in hardware. */
    pkt.pstart[48] = 0xFF;

    if (pipeline)
      err = ofdpaPktSend(&pkt, OFDPA_PKT_LOOKUP, portNum, rxPkt.inPortNum);
    else
      err = ofdpaPktSend(&pkt, 0, portNum, 0);
    if (err != OFDPA_E_NONE)
    {
      printf("\npacket send failed with error %d\r\n", err);
    }
    rc = ofdpaPktReceive(tv, &rxPkt);
  }

  exit(0);
}
コード例 #7
0
ファイル: client_event.c プロジェクト: rizard/ofdpa-2.0
/* Arguments as follows:
 * argv[1] - how long to block on receive, in seconds. -1 to block forever.
 */
int main(int argc, char *argv[])
{
  char client_name[] = "ofdpa event client";
  OFDPA_ERROR_t rc;
  int32_t wait;

  struct timeval timeout;
  struct timeval *tv = NULL;

  time_t startTime;
  time_t currentTime;
  int32_t elapsedSeconds;

  ofdpaGroupEntry_t l2IfaceGroup;
  ofdpaGroupBucketEntry_t bucket;

  ofdpaFlowEntry_t flow;
  ofdpaFlowEvent_t flowEventData;

  ofdpaPortEvent_t portEventData;
  int i;

  if (argc == 2)
  {
    wait = atoi(argv[1]);
  }
  else
  {
    wait = -1;
  }

  rc = ofdpaClientInitialize(client_name);
  if (rc != OFDPA_E_NONE)
  {
    return rc;
  }
  rc = ofdpaClientEventSockBind();
  if (rc != OFDPA_E_NONE)
  {
    return rc;
  }
  rc = ofdpaClientPktSockBind();
  if (rc != OFDPA_E_NONE)
  {
    return rc;
  }

  if (wait >= 0)
  {
    timeout.tv_sec = wait;
    timeout.tv_usec = 0;
    tv = &timeout;
    printf("\nclient_event: using wait time %d seconds for event\n", wait);
  }
  else
    printf("\nclient_event: waiting indefinitely for events\n");

  /* first clear out out any existing flows in the Bridging table */
  memset(&flow, 0, sizeof(flow));
  flow.tableId = OFDPA_FLOW_TABLE_ID_BRIDGING;

  /* wait if OFDPA process not ready for RPC */
  while (ofdpaFlowNextGet(&flow, &flow) == OFDPA_E_RPC)
  {
    printf("\nclient_event: waiting for OF-DPA RPC server to respond\n");
    usleep(1000000);
  }

  do
  {
    (void)ofdpaFlowDelete(&flow);
  } while (ofdpaFlowNextGet(&flow, &flow) == OFDPA_E_NONE);

  /* build and add some flows with various hard timeout values */

  /* bridging entries need an L2 Interface group */
  ofdpaGroupTypeSet(&l2IfaceGroup.groupId, OFDPA_GROUP_ENTRY_TYPE_L2_INTERFACE);
  ofdpaGroupVlanSet(&l2IfaceGroup.groupId, 10);
  ofdpaGroupPortIdSet(&l2IfaceGroup.groupId, 1);

  (void)ofdpaGroupDelete(l2IfaceGroup.groupId);

  rc = ofdpaGroupAdd(&l2IfaceGroup);
  if (rc != OFDPA_E_NONE)
  {
    printf("\nError creating required L2 Interface Group entry. rc = %d", rc);
    return(3);
  }

  memset(&bucket, 0, sizeof(bucket));
  bucket.groupId = l2IfaceGroup.groupId;
  bucket.bucketIndex = 1;
  bucket.bucketData.l2Interface.outputPort = 1;
  rc = ofdpaGroupBucketEntryAdd(&bucket);
  if (rc != OFDPA_E_NONE)
  {
    printf("\nError creating required L2 Interface Group entry bucket. rc = %d", rc);
    return(3);
  }

  memset(&flow, 0, sizeof(flow));
  flow.tableId = OFDPA_FLOW_TABLE_ID_BRIDGING;
  flow.flowData.bridgingFlowEntry.gotoTableId = OFDPA_FLOW_TABLE_ID_ACL_POLICY;
  flow.flowData.bridgingFlowEntry.match_criteria.destMac.addr[5] = 0x01;
  flow.flowData.bridgingFlowEntry.match_criteria.destMacMask.addr[0] = 0xff;
  flow.flowData.bridgingFlowEntry.match_criteria.destMacMask.addr[1] = 0xff;
  flow.flowData.bridgingFlowEntry.match_criteria.destMacMask.addr[2] = 0xff;
  flow.flowData.bridgingFlowEntry.match_criteria.destMacMask.addr[3] = 0xff;
  flow.flowData.bridgingFlowEntry.match_criteria.destMacMask.addr[4] = 0xff;
  flow.flowData.bridgingFlowEntry.match_criteria.destMacMask.addr[5] = 0xff;
  flow.flowData.bridgingFlowEntry.match_criteria.vlanId = 100;
  flow.flowData.bridgingFlowEntry.match_criteria.vlanIdMask = OFDPA_VID_PRESENT | OFDPA_VID_EXACT_MASK;
  flow.flowData.bridgingFlowEntry.groupID = l2IfaceGroup.groupId;

  flow.hard_time = 5;

  if ((rc = ofdpaFlowAdd(&flow)) != OFDPA_E_NONE)
  {
    printf("client_event: ofdpaFlowAdd failed for first flow: rc = %d\n", rc);
    /* no sense in continuing if we cannot add the first test flow */
    return(-1);
  }

  /* build up a second flow with a later hard time value */
  flow.flowData.bridgingFlowEntry.match_criteria.vlanId++;
  flow.hard_time = 15;
  if (ofdpaFlowAdd(&flow) != OFDPA_E_NONE)
  {
    printf("client_event: ofdpaFlowAdd failed for second flow: rc = %d\n", rc);
    /* forge ahead */
  }

  /* build up a flow with a idle time value that expires before the second hard time flow */
  flow.flowData.bridgingFlowEntry.match_criteria.vlanId++;
  flow.hard_time = 0;
  flow.idle_time = 10;
  if (ofdpaFlowAdd(&flow) != OFDPA_E_NONE)
  {
    printf("client_event: ofdpaFlowAdd failed: rc = %d\n", rc);
    /* forge ahead */
  }

  /* build up a flow with a idle time value AND a hard time value to see
     if we can get both event types valid for the same flow simultaneously
   */
  flow.flowData.bridgingFlowEntry.match_criteria.vlanId++;
  flow.hard_time = 12;
  flow.idle_time = 12;
  if (ofdpaFlowAdd(&flow) != OFDPA_E_NONE)
  {
    printf("client_event: ofdpaFlowAdd failed: rc = %d\n", rc);
    /* forge ahead */
  }
  flow.idle_time = 0;

  /* build up a group of flows with the same hard time value to see if we can
     generate multiple flow events sharing the same event notification
   */
  flow.hard_time = 20;
  for (i=0; i<10; i++)
  {
    flow.flowData.bridgingFlowEntry.match_criteria.vlanId++;
    if (ofdpaFlowAdd(&flow) != OFDPA_E_NONE)
    {
      printf("client_event: ofdpaFlowAdd failed in flow add loop: rc = %d, i = %d\n", rc, i);
      /* forge ahead */
    }
  }

  printf("client_event: waiting for event notifications...\n");
  time(&startTime);
  while ((rc = ofdpaEventReceive(tv)) == OFDPA_E_NONE)
  {
    time(&currentTime);
    elapsedSeconds = currentTime - startTime;
    printf("client_event: received event notification (elapsed time: %d seconds)\n",
           elapsedSeconds);

    memset(&flowEventData, 0, sizeof(flowEventData));
    flowEventData.flowMatch.tableId = OFDPA_FLOW_TABLE_ID_BRIDGING;

    while (ofdpaFlowEventNextGet(&flowEventData) == OFDPA_E_NONE)
    {
      printf("client_event: retrieved aged flow: tableId = %d, eventMask = %x\n",
             flowEventData.flowMatch.tableId, flowEventData.eventMask);
      printf("    flow data: vlanId = %d\n",
             flowEventData.flowMatch.flowData.bridgingFlowEntry.match_criteria.vlanId & OFDPA_VID_EXACT_MASK);

      if ((rc = ofdpaFlowDelete(&flowEventData.flowMatch)) != OFDPA_E_NONE)
        printf("client_event: ofdpaFlowDelete rc = %d\n", rc);
      else
        printf("client_event: successfully deleted aged flow\n");
    }

    memset(&portEventData, 0, sizeof(portEventData));
    while (ofdpaPortEventNextGet(&portEventData) == OFDPA_E_NONE)
    {
      printf("client_event: retrieved port event: port no = %d [0x%x], eventMask = 0x%x, state = %d\n",
             portEventData.portNum, portEventData.portNum, portEventData.eventMask, portEventData.state);
    }
  }

  printf("client_event: ofdpaEventReceive rc = %d\n", rc);

  /* clean up group entry */
  (void)ofdpaGroupDelete(l2IfaceGroup.groupId);

  return 0;
}