diff --git a/server/Test/NetworkLayer3Tests.php b/server/Test/NetworkLayer3Tests.php
index b827a51..cb14e3a 100644
--- a/server/Test/NetworkLayer3Tests.php
+++ b/server/Test/NetworkLayer3Tests.php
@@ -47,7 +47,7 @@ foreach ($listFloatingIp as $floatIp){
echo "";
-// Liste des floatingip
+// get floatingip
echo "Get floatingip : ";
$App->setPostParam('id', $id);
$networkLayer3->action("getFloatingIp");
@@ -70,12 +70,14 @@ if(!isset($float)){
echo "";
*/
+
/*
// Suppression d'une ip flotante
$App->setPostParam('id', $id);
$networkLayer3->action("deleteFloatingIp");
*/
+
// Liste des floatingip
echo "Liste des floatingip : ";
$networkLayer3->action("listFloatingIp");
@@ -83,6 +85,62 @@ $listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
foreach ($listFloatingIp as $floatIp){
echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."
";
}
+echo "";
+// Liste des routeurs
+echo "Liste des routeurs : ";
+$networkLayer3->action("listRouters");
+$listRouters = json_decode($App->show(), true)["NetworkLayer3"];
+foreach ($listRouters as $router){
+ echo $router['name']." ".$router['id']."
";
+ if(strcmp($router['name'], "Test")){
+ $id = $router['id'];
+ }
+}
+echo "";
+
+
+// get floatingip
+echo "Get router : ";
+$App->setPostParam('id', $id);
+$networkLayer3->action("getRouter");
+$getRouter = json_decode($App->show(), true)["NetworkLayer3"];
+echo $getRouter['id']."
";
+echo "";
+
+
+/*
+// Création d'un routeur'
+$opt = array();
+$optGate = array();
+$optGate['networkId'] = "251b4641-20ff-4a72-8549-1758788b51ce";
+$opt['externalGatewayInfo'] = $optGate;
+$opt['name'] = "Test";
+$App->setPostParam('opt', $opt);
+$networkLayer3->action("createRouter");
+$r = json_decode($App->show(), true)["NetworkLayer3"];
+if(!isset($r)){
+ echo "Erreur pendant la création";
+}
+echo "";
+*/
+
+
+/*
+// Suppression d'un routeur
+$App->setPostParam('id', $id);
+$networkLayer3->action("deleteRouter");
+echo "";
+*/
+
+
+// Liste des routeurs
+echo "Liste des routeurs : ";
+$networkLayer3->action("listRouters");
+$listRouters = json_decode($App->show(), true)["NetworkLayer3"];
+foreach ($listRouters as $router){
+ echo $router['name']." ".$router['id']."
";
+}
+
?>
\ No newline at end of file
diff --git a/server/core/NetworkLayer3.php b/server/core/NetworkLayer3.php
index 28d27b4..30e8a78 100755
--- a/server/core/NetworkLayer3.php
+++ b/server/core/NetworkLayer3.php
@@ -89,7 +89,7 @@ class networkLayer3 {
/**
* Create a new floating IP adress
*
- * @param array $opt Options for the floating ip creation (floatingipo and floating network id are required, others are optionals)
+ * @param array $opt Options for the floating ip creation (floatingNetworkId is required)
*
* @return floatingip
*/
@@ -108,19 +108,14 @@ class networkLayer3 {
$this->app->setOutput("NetworkLayer3", $floatingip);
}
}catch(BadResponseError $e){
- echo $e."";
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
- echo $e."";
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
- echo $e."";
$this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
- echo $e."";
$this->app->getErrorInstance()->NotImplementedHandler($e);
}catch(Exception $e){
- echo $e->getMessage()."";
$this->app->getErrorInstance()->OtherException($e);
}
}
@@ -150,7 +145,7 @@ class networkLayer3 {
// Verification if id exists
$result = null;
foreach ($res as $f) {
- if(strcmp($res['id'], $id)){
+ if(strcmp($f->id, $id)){
$result = $f;
}
@@ -162,7 +157,6 @@ class networkLayer3 {
$res = $this->libClass->getFloatingIp($id);
$this->app->setOutput("NetworkLayer3", $res);
}
-
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
@@ -181,7 +175,7 @@ class networkLayer3 {
*
* @param id the id of the floatingip to update
*
- * @return Image
+ * @return void
*/
private function updateFloatingIp(){
$id = $this->app->getPostParam("id");
@@ -201,7 +195,7 @@ class networkLayer3 {
// Verification if id exists
$result = null;
foreach ($res as $f) {
- if(strcmp($res['id'], $id)){
+ if(strcmp($f->id, $id)){
$result = $f;
}
@@ -212,8 +206,6 @@ class networkLayer3 {
}else{
$result->update();
}
-
-
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
@@ -251,7 +243,7 @@ class networkLayer3 {
// Verification if id exists
$result = null;
foreach ($res as $f) {
- if(strcmp($res['id'], $id)){
+ if(strcmp($f->id, $id)){
$result = $f;
}
@@ -300,7 +292,7 @@ class networkLayer3 {
// Verification if id exists
$result = null;
foreach ($res as $f) {
- if(strcmp($res['id'], $id)){
+ if(strcmp($f->id, $id)){
$result = $f;
}
@@ -323,4 +315,217 @@ class networkLayer3 {
$this->app->getErrorInstance()->OtherException($e);
}
}
+
+
+
+ /**
+ * Create a new router
+ *
+ * @param array $opt Options for the new router
+ * externalGatewayInfo[] required (only the param networkId in the tab)
+ * adminStateUp (optionnal)
+ * name (optionnal)
+ *
+ * @return router
+ */
+ private function createRouter(){
+ $opt = $this->app->getPostParam("opt");
+
+ if(!isset($opt)){
+ $this->app->setOutput("Error", "Incorrect parameter opt");
+ }
+ try{
+ $router = $this->libClass->createRouter($opt);
+
+ if(!isset($router)){
+ $this->app->setOutput("Error", "Unknowing error during floating ip creation");
+ }else{
+ $this->app->setOutput("NetworkLayer3", $router);
+ }
+ }catch(BadResponseError $e){
+ $this->app->getErrorInstance()->BadResponseHandler($e);
+ }catch(UserInputError $e){
+ $this->app->getErrorInstance()->UserInputHandler($e);
+ }catch(BaseError $e){
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
+ }catch(NotImplementedError $e){
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
+ }catch(Exception $e){
+ $this->app->getErrorInstance()->OtherException($e);
+ }
+ }
+
+
+ /**
+ * List routers
+ *
+ * @return list of the routers
+ */
+ private function listRouters(){
+ try{
+ $result = array();
+ $l = $this->libClass->listRouters();
+ foreach ($l as $tmp) {
+ $result[] = $tmp;
+ }
+
+ $this->app->setOutput("NetworkLayer3", $result);
+ }catch(BadResponseError $e){
+ $this->app->getErrorInstance()->BadResponseHandler($e);
+ }catch(UserInputError $e){
+ $this->app->getErrorInstance()->UserInputHandler($e);
+ }catch(BaseError $e){
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
+ }catch(NotImplementedError $e){
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
+ }catch(Exception $e){
+ $this->app->getErrorInstance()->OtherException($e);
+ }
+ }
+
+
+ /**
+ * Show router details
+ *
+ * @param String id the id of the router
+ *
+ * @return router details
+ */
+ private function getRouter(){
+ $id = $this->app->getPostParam("id");
+ if(!isset($id)){
+ $this->app->setOutput("Error", "Incorrect parameter opt");
+ }
+ try{
+ // List of routers
+ $res = array();
+ $l = $this->libClass->listRouters();
+ foreach ($l as $tmp) {
+ $res[] = $tmp;
+ }
+
+ // Verification if id exists
+ $result = null;
+ foreach ($res as $f) {
+ if(strcmp($f->id, $id)){
+ $result = $f;
+ }
+ }
+
+ if(!isset($result)){ // If id doesn't exists
+ $this->app->setOutput("Error", "Unknow id");
+ }else{ // If id exists
+ $res = $this->libClass->getRouter($id);
+ $this->app->setOutput("NetworkLayer3", $res);
+ }
+ }catch(BadResponseError $e){
+ $this->app->getErrorInstance()->BadResponseHandler($e);
+ }catch(UserInputError $e){
+ $this->app->getErrorInstance()->UserInputHandler($e);
+ }catch(BaseError $e){
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
+ }catch(NotImplementedError $e){
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
+ }catch(Exception $e){
+ $this->app->getErrorInstance()->OtherException($e);
+ }
+ }
+
+
+ /**
+ * Delete a router
+ *
+ * @param string router the router to delete
+ *
+ * @return void
+ */
+ private function deleteRouter(){
+ $id = $this->app->getPostParam("id");
+
+ if(!isset($id)){
+ $this->app->setOutput("Error", "Incorrect parameter opt");
+ }
+ try{
+ // List of routers
+ $res = array();
+ $l = $this->libClass->listRouters();
+ foreach ($l as $tmp) {
+ $res[] = $tmp;
+ }
+
+ // Verification if id exists
+ $result = null;
+ foreach ($res as $f) {
+ if(strcmp($f->id, $id)){
+ $result = $f;
+ }
+ }
+
+ if(!isset($result)){ // If id doesn't exists
+ $this->app->setOutput("Error", "Unknowing router id");
+ }else{
+ $result->delete();
+ }
+ }catch(BadResponseError $e){
+ $this->app->getErrorInstance()->BadResponseHandler($e);
+ }catch(UserInputError $e){
+ $this->app->getErrorInstance()->UserInputHandler($e);
+ }catch(BaseError $e){
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
+ }catch(NotImplementedError $e){
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
+ }catch(Exception $e){
+ $this->app->getErrorInstance()->OtherException($e);
+ }
+ }
+
+
+ /**
+ * Update router
+ *
+ * @param id the id of the floatingip to update
+ *
+ * @return void
+ */
+ private function updateRouter(){
+ $id = $this->app->getPostParam("id");
+
+ if(!isset($id)){
+ $this->app->setOutput("Error", "Incorrect parameter opt");
+ }
+ try{
+
+ // List of floating IPs
+ $res = array();
+ $l = $this->libClass->listRouters();
+ foreach ($l as $tmp) {
+ $res[] = $tmp;
+ }
+
+ // Verification if id exists
+ $result = null;
+ foreach ($res as $f) {
+ if(strcmp($f->id, $id)){
+ $result = $f;
+
+ }
+ }
+
+ if(!isset($result)){ // If id doesn't exists
+ $this->app->setOutput("Error", "Unknowing floatingip id");
+ }else{
+ $result->update();
+ }
+ }catch(BadResponseError $e){
+ $this->app->getErrorInstance()->BadResponseHandler($e);
+ }catch(UserInputError $e){
+ $this->app->getErrorInstance()->UserInputHandler($e);
+ }catch(BaseError $e){
+ $this->app->getErrorInstance()->BaseErrorHandler($e);
+ }catch(NotImplementedError $e){
+ $this->app->getErrorInstance()->NotImplementedHandler($e);
+ }catch(Exception $e){
+ $this->app->getErrorInstance()->OtherException($e);
+ }
+ }
}