{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "341ff8eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import libraries\n",
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8fb1a1e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_pcap_exports(filepath, testname, title):\n",
    "    # build file paths\n",
    "    em1 = (\"{}\\\\{}.em1.csv\".format(filepath, testname))\n",
    "    em2 = (\"{}\\\\{}.em2.csv\".format(filepath, testname))\n",
    "    \n",
    "    # read files into dataframe\n",
    "    df1 = pd.read_csv(em1, sep=',')\n",
    "    df2 = pd.read_csv(em2, sep=',')\n",
    "    \n",
    "    # filter out non-mptcp data\n",
    "    df1.drop(df1.index[df1['Source'] != '172.16.1.2'], inplace=True)\n",
    "    df1.drop(df1.index[df1['Destination'] != '172.16.3.2'], inplace=True)\n",
    "    df2.drop(df2.index[df2['Source'] != '172.16.2.2'], inplace=True)\n",
    "    df2.drop(df2.index[df2['Destination'] != '172.16.3.2'], inplace=True)\n",
    "    \n",
    "    # specify number of seconds to group data by\n",
    "    group_by_seconds = 2\n",
    "    \n",
    "    # convert bytes to megabits\n",
    "    df1['Length'] = df1['Length'] / 1024 / 1024 * 8 / group_by_seconds\n",
    "    df2['Length'] = df2['Length'] / 1024 / 1024 * 8 / group_by_seconds\n",
    "    \n",
    "    # group data into intervals\n",
    "    df1['Time'] = np.floor(df1['Time'] / group_by_seconds) * group_by_seconds\n",
    "    df1 = df1.groupby(['Time']).sum()\n",
    "    df2['Time'] = np.floor(df2['Time'] / group_by_seconds) * group_by_seconds\n",
    "    df2 = df2.groupby(['Time']).sum()\n",
    "    \n",
    "    plt.plot(df1['Length'], label = \"Flow 1\")\n",
    "    plt.plot(df2['Length'], label = \"Flow 2\")\n",
    "\n",
    "    plt.legend(loc='best', ncol=2)\n",
    "\n",
    "    plt.xlabel(\"Time (s)\")\n",
    "    plt.ylabel(\"Throughput (Mbps)\")\n",
    "\n",
    "    plt.ylim([0, 8])\n",
    "    \n",
    "    plt.title(title)\n",
    "    \n",
    "    plt.show()\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4cd70534",
   "metadata": {},
   "source": [
    "# Scenario 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "ddbf7837",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 39796 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 41952 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 45876 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 47824 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 46564 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_pcap_exports(\"scenario1\\\\data\", \"untrained\", \"Scenario 1, Untrained Model\")\n",
    "plot_pcap_exports(\"scenario1\\\\data\", \"offline\", \"Scenario 1, Offline Model\")\n",
    "plot_pcap_exports(\"scenario1\\\\data\", \"online\", \"Scenario 1, Online Model\")\n",
    "plot_pcap_exports(\"scenario1\\\\data\", \"global\", \"Scenario 1, Global Model\")\n",
    "plot_pcap_exports(\"scenario1\\\\data\", \"global_trained\", \"Scenario 1, Global Trained Model\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acfbb919",
   "metadata": {},
   "source": [
    "# Scenario 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "68a3b9d5",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 38688 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 39532 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 34708 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 44280 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 39248 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_pcap_exports(\"scenario2\\\\data\", \"untrained\", \"Scenario 2, Untrained Model\")\n",
    "plot_pcap_exports(\"scenario2\\\\data\", \"offline\", \"Scenario 2, Offline Model\")\n",
    "plot_pcap_exports(\"scenario2\\\\data\", \"online\", \"Scenario 2, Online Model\")\n",
    "plot_pcap_exports(\"scenario2\\\\data\", \"global\", \"Scenario 2, Global Model\")\n",
    "plot_pcap_exports(\"scenario2\\\\data\", \"global_trained\", \"Scenario 2, Global Trained Model\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97abbdba",
   "metadata": {},
   "source": [
    "# Scenario 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "1b369953",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 49960 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 58708 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 46456 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 72872 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 56956 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_pcap_exports(\"scenario3\\\\data\", \"untrained\", \"Scenario 3, Untrained Model\")\n",
    "plot_pcap_exports(\"scenario3\\\\data\", \"offline\", \"Scenario 3, Offline Model\")\n",
    "plot_pcap_exports(\"scenario3\\\\data\", \"online\", \"Scenario 3, Online Model\")\n",
    "plot_pcap_exports(\"scenario3\\\\data\", \"global\", \"Scenario 3, Global Model\")\n",
    "plot_pcap_exports(\"scenario3\\\\data\", \"global_trained\", \"Scenario 3, Global Trained Model\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
