kytos-ng / sdntrace_cp

MIT License
1 stars 6 forks source link

Add PUT traces endpoint and functionality match_and_apply #47

Closed gretelliz closed 2 years ago

gretelliz commented 2 years ago

This PR is related to issues #43 #44 #45 #46 It is now possible to request stored flows from flow_manager. match_an_apply has been moved from flow_stats. Added new PUT /traces endpoint for bulk requests.

This endpoint returns a list of traces organized by switches. The specification is added in openapi.yml. Examples of requests and responses:

[
  {
    "trace": {
      "switch": {
        "dpid": "00:00:00:00:00:00:00:01",
        "in_port": 1
      },
      "eth": {
        "dl_vlan": 100,
      },
    }
  },
  {
    "trace": {
      "switch": {
        "dpid": "00:00:00:00:00:00:00:03",
        "in_port": 1
      },
      "eth": {
        "dl_vlan": 100,
       },
    }
  }
]

Response:

{
    "00:00:00:00:00:00:00:01": [
        [
            {
                "dpid": "00:00:00:00:00:00:00:01",
                "port": 1,
                "time": "2022-10-13 13:19:36.684592",
                "type": "starting",
                "vlan": 100
            },
            {
                "dpid": "00:00:00:00:00:00:00:02",
                "port": 2,
                "time": "2022-10-13 13:19:36.684857",
                "type": "trace",
                "vlan": 2813
            },
            {
                "dpid": "00:00:00:00:00:00:00:03",
                "port": 2,
                "time": "2022-10-13 13:19:36.685209",
                "type": "trace",
                "vlan": 426
            }
        ]
    ],
    "00:00:00:00:00:00:00:03": [
        [
            {
                "dpid": "00:00:00:00:00:00:00:03",
                "port": 1,
                "time": "2022-10-13 13:19:36.685563",
                "type": "starting",
                "vlan": 100
            },
            {
                "dpid": "00:00:00:00:00:00:00:02",
                "port": 3,
                "time": "2022-10-13 13:19:36.685718",
                "type": "trace",
                "vlan": 4001
            },
            {
                "dpid": "00:00:00:00:00:00:00:01",
                "port": 2,
                "time": "2022-10-13 13:19:36.685955",
                "type": "trace",
                "vlan": 3824
            }
        ]
    ]
}

It has also been validated that one response is only returned for equal elements within a list of requests. The previous case, where only one trace is requested, remains with the same structure.

Please consider function map_flows, and comment if you agree.

gretelliz commented 2 years ago

Hi @viniarck I have done changes according to your suggestions.

There is now a separate new function for the /traces endpoint. I removed the variable self.stored_flows. I also removed the translation to vlan_vid. I removed the lots of nested of ifs as you suggested.

viniarck commented 2 years ago

@gretelliz #47 (comment),

Thanks for pushing the last commits, nice to see how this is shaping up, I've just reviewed and followed up. Also, when it's ready for another review please explore it locally with mef_eline with an EVC with both PUT /traces and PUT /trace endpoints and let us know how it went.

@gretelliz thanks for pushing these latest commits, I've just closed the threads you've addressed. The only thing renaming is to explore locally and ideally re-run existing e2e tests related to sdntrace_cp, it'd be great to also have e2e coverage for this new endpoint.

gretelliz commented 2 years ago

I explored the last commit locally with an EVC for both PUT /traces and PUT /trace endpoints:

It seems to be fine. Here you can see some examples:

Steps:

  1. Create a new circuit:

request:

{
            "name": "Vlan_400" ,
            "enabled": true,
            "dynamic_backup_path": true,
            "uni_a": {
                "interface_id": "00:00:00:00:00:00:00:01:1"
            },
            "uni_z": {
                "interface_id": "00:00:00:00:00:00:00:03:1"
            }
}

response:

{
    "circuit_id": "d05f0d7128c447"
}
  1. Test PUT /trace endpoint:

request:

  {
    "trace": {
      "switch": {
        "dpid": "00:00:00:00:00:00:00:01",
        "in_port": 1
      },
      "eth": {
        "dl_vlan": 100
      }
    }
  }

response:

{
    "result": [
        {
            "dpid": "00:00:00:00:00:00:00:01",
            "port": 1,
            "time": "2022-10-19 14:11:44.163363",
            "type": "starting",
            "vlan": 100
        },
        {
            "dpid": "00:00:00:00:00:00:00:02",
            "port": 2,
            "time": "2022-10-19 14:11:44.163428",
            "type": "trace",
            "vlan": 1762
        }
    ]
}
  1. Test PUT /traces endpoint:

request 1: Different entries

[
  {
    "trace": {
      "switch": {
        "dpid": "00:00:00:00:00:00:00:01",
        "in_port": 1
      },
      "eth": {
        "dl_vlan": 100
      }
    }
  },
  {
    "trace": {
      "switch": {
        "dpid": "00:00:00:00:00:00:00:03",
        "in_port": 1
      },
      "eth": {
        "dl_vlan": 100
      }
    }
  }
]

response:

{
    "00:00:00:00:00:00:00:01": [
        [
            {
                "dpid": "00:00:00:00:00:00:00:01",
                "port": 1,
                "time": "2022-10-19 14:14:42.673497",
                "type": "starting",
                "vlan": 100
            },
            {
                "dpid": "00:00:00:00:00:00:00:02",
                "port": 2,
                "time": "2022-10-19 14:14:42.673548",
                "type": "trace",
                "vlan": 1762
            }
        ]
    ],
    "00:00:00:00:00:00:00:03": [
        [
            {
                "dpid": "00:00:00:00:00:00:00:03",
                "port": 1,
                "time": "2022-10-19 14:14:42.673569",
                "type": "starting",
                "vlan": 100
            },
            {
                "dpid": "00:00:00:00:00:00:00:02",
                "port": 3,
                "time": "2022-10-19 14:14:42.673583",
                "type": "trace",
                "vlan": 279
            },
            {
                "dpid": "00:00:00:00:00:00:00:01",
                "port": 2,
                "time": "2022-10-19 14:14:42.673605",
                "type": "trace",
                "vlan": 1458
            }
        ]
    ]
}

request 2: Same dpid and different ports in entries

[
  {
    "trace": {
      "switch": {
        "dpid": "00:00:00:00:00:00:00:01",
        "in_port": 2
      },
      "eth": {
        "dl_vlan": 100
      }
    }
  },
  {
    "trace": {
      "switch": {
        "dpid": "00:00:00:00:00:00:00:01",
        "in_port": 1
      },
      "eth": {
        "dl_vlan": 100
      }
    }
  }
]

response:

{
    "00:00:00:00:00:00:00:01": [
        [
            {
                "dpid": "00:00:00:00:00:00:00:01",
                "port": 2,
                "time": "2022-10-19 14:16:58.703696",
                "type": "starting",
                "vlan": 100
            }
        ],
        [
            {
                "dpid": "00:00:00:00:00:00:00:01",
                "port": 1,
                "time": "2022-10-19 14:16:58.703841",
                "type": "starting",
                "vlan": 100
            },
            {
                "dpid": "00:00:00:00:00:00:00:02",
                "port": 2,
                "time": "2022-10-19 14:16:58.703872",
                "type": "trace",
                "vlan": 1762
            }
        ]
    ]
}

request 3: Same entry twice

[
  {
    "trace": {
      "switch": {
        "dpid": "00:00:00:00:00:00:00:01",
        "in_port": 1
      },
      "eth": {
        "dl_vlan": 100
      }
    }
  },
  {
    "trace": {
      "switch": {
        "dpid": "00:00:00:00:00:00:00:01",
        "in_port": 1
      },
      "eth": {
        "dl_vlan": 100
      }
    }
  }
]

response:

{
    "00:00:00:00:00:00:00:01": [
        [
            {
                "dpid": "00:00:00:00:00:00:00:01",
                "port": 1,
                "time": "2022-10-19 14:17:41.065475",
                "type": "starting",
                "vlan": 100
            },
            {
                "dpid": "00:00:00:00:00:00:00:02",
                "port": 2,
                "time": "2022-10-19 14:17:41.065531",
                "type": "trace",
                "vlan": 1762
            }
        ]
    ]
}
gretelliz commented 2 years ago

Great! @viniarck. I will close this PR here and open a new issue for the e2e test.