From 07e096af6c5e32f937f028f5c28ce73bddeca0a3 Mon Sep 17 00:00:00 2001 From: alphayax Date: Sat, 28 May 2016 15:07:31 +0200 Subject: [PATCH] Add Switch API --- README.md | 4 + TODO.md | 2 +- freebox/api/v3/models/SwitchPort/Config.php | 60 ++++ freebox/api/v3/models/SwitchPort/Stats.php | 311 ++++++++++++++++++ freebox/api/v3/models/SwitchPort/Status.php | 91 +++++ .../v3/services/config/SwitchPort/Config.php | 40 +++ .../v3/services/config/SwitchPort/Stats.php | 27 ++ .../v3/services/config/SwitchPort/Status.php | 25 ++ .../v3/symbols/SwitchPort/Config/Duplex.php | 19 ++ .../v3/symbols/SwitchPort/Config/Speed.php | 22 ++ .../v3/symbols/SwitchPort/Status/Duplex.php | 16 + .../api/v3/symbols/SwitchPort/Status/Link.php | 16 + .../v3/symbols/SwitchPort/Status/Speed.php | 19 ++ 13 files changed, 651 insertions(+), 1 deletion(-) create mode 100644 freebox/api/v3/models/SwitchPort/Config.php create mode 100644 freebox/api/v3/models/SwitchPort/Stats.php create mode 100644 freebox/api/v3/models/SwitchPort/Status.php create mode 100644 freebox/api/v3/services/config/SwitchPort/Config.php create mode 100644 freebox/api/v3/services/config/SwitchPort/Stats.php create mode 100644 freebox/api/v3/services/config/SwitchPort/Status.php create mode 100644 freebox/api/v3/symbols/SwitchPort/Config/Duplex.php create mode 100644 freebox/api/v3/symbols/SwitchPort/Config/Speed.php create mode 100644 freebox/api/v3/symbols/SwitchPort/Status/Duplex.php create mode 100644 freebox/api/v3/symbols/SwitchPort/Status/Link.php create mode 100644 freebox/api/v3/symbols/SwitchPort/Status/Speed.php diff --git a/README.md b/README.md index ea9a3af..602ff13 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,10 @@ Jusqu'a présent, les fonctionalités suivantes ont été implémentées : - Network Share - Samba - Afp + - Switch + - Statistics + - Status + - Config - System - LCD - NAT diff --git a/TODO.md b/TODO.md index 6162c11..d0569b2 100644 --- a/TODO.md +++ b/TODO.md @@ -32,7 +32,7 @@ - ~~LCD~~ - ~~Network Share~~ - ~~UPnP AV~~ - - Switch + - ~~Switch~~ - Wi-Fi - ~~System~~ - VPN Server [UNSTABLE] diff --git a/freebox/api/v3/models/SwitchPort/Config.php b/freebox/api/v3/models/SwitchPort/Config.php new file mode 100644 index 0000000..5d850b1 --- /dev/null +++ b/freebox/api/v3/models/SwitchPort/Config.php @@ -0,0 +1,60 @@ +id; + } + + /** + * @return string + * @see symbols\SwitchPort\Config\Duplex + */ + public function getDuplex() { + return $this->duplex; + } + + /** + * @param string $duplex + * @see symbols\SwitchPort\Config\Duplex + */ + public function setDuplex($duplex) { + $this->duplex = $duplex; + } + + /** + * @return int|string + * @see symbols\SwitchPort\Config\Speed + */ + public function getSpeed() { + return $this->speed; + } + + /** + * @param int|string $speed + * @see symbols\SwitchPort\Config\Speed + */ + public function setSpeed($speed) { + $this->speed = $speed; + } + +} diff --git a/freebox/api/v3/models/SwitchPort/Stats.php b/freebox/api/v3/models/SwitchPort/Stats.php new file mode 100644 index 0000000..0141a9b --- /dev/null +++ b/freebox/api/v3/models/SwitchPort/Stats.php @@ -0,0 +1,311 @@ +rx_bad_bytes; + } + + /** + * @return int + */ + public function getRxBroadcastPackets() { + return $this->rx_broadcast_packets; + } + + /** + * @return int + */ + public function getRxBytesRate() { + return $this->rx_bytes_rate; + } + + /** + * @return int + */ + public function getRxErrPackets() { + return $this->rx_err_packets; + } + + /** + * @return int + */ + public function getRxFcsPackets() { + return $this->rx_fcs_packets; + } + + /** + * @return int + */ + public function getRxFragmentsPackets() { + return $this->rx_fragments_packets; + } + + /** + * @return int + */ + public function getRxGoodBytes() { + return $this->rx_good_bytes; + } + + /** + * @return int + */ + public function getRxGoodPackets() { + return $this->rx_good_packets; + } + + /** + * @return int + */ + public function getRxJabberPackets() { + return $this->rx_jabber_packets; + } + + /** + * @return int + */ + public function getRxMulticastPackets() { + return $this->rx_multicast_packets; + } + + /** + * @return int + */ + public function getRxOversizePackets() { + return $this->rx_oversize_packets; + } + + /** + * @return int + */ + public function getRxPacketsRate() { + return $this->rx_packets_rate; + } + + /** + * @return int + */ + public function getRxPause() { + return $this->rx_pause; + } + + /** + * @return int + */ + public function getRxUndersizePackets() { + return $this->rx_undersize_packets; + } + + /** + * @return int + */ + public function getRxUnicastPackets() { + return $this->rx_unicast_packets; + } + + /** + * @return int + */ + public function getTxBroadcastPackets() { + return $this->tx_broadcast_packets; + } + + /** + * @return int + */ + public function getTxBytes() { + return $this->tx_bytes; + } + + /** + * @return int + */ + public function getTxBytesRate() { + return $this->tx_bytes_rate; + } + + /** + * @return int + */ + public function getTxCollisions() { + return $this->tx_collisions; + } + + /** + * @return int + */ + public function getTxDeferred() { + return $this->tx_deferred; + } + + /** + * @return int + */ + public function getTxExcessive() { + return $this->tx_excessive; + } + + /** + * @return int + */ + public function getTxFcs() { + return $this->tx_fcs; + } + + /** + * @return int + */ + public function getTxLate() { + return $this->tx_late; + } + + /** + * @return int + */ + public function getTxMulticastPackets() { + return $this->tx_multicast_packets; + } + + /** + * @return int + */ + public function getTxMultiple() { + return $this->tx_multiple; + } + + /** + * @return int + */ + public function getTxPackets() { + return $this->tx_packets; + } + + /** + * @return int + */ + public function getTxPacketsRate() { + return $this->tx_packets_rate; + } + + /** + * @return int + */ + public function getTxPause() { + return $this->tx_pause; + } + + /** + * @return int + */ + public function getTxSingle() { + return $this->tx_single; + } + + /** + * @return int + */ + public function getTxUnicastPackets() { + return $this->tx_unicast_packets; + } + +} diff --git a/freebox/api/v3/models/SwitchPort/Status.php b/freebox/api/v3/models/SwitchPort/Status.php new file mode 100644 index 0000000..af829e0 --- /dev/null +++ b/freebox/api/v3/models/SwitchPort/Status.php @@ -0,0 +1,91 @@ +id; + } + + /** + * @return string + * @see symbols\SwitchPort\Status\Link + */ + public function getLink() { + return $this->link; + } + + /** + * @return string + * @see symbols\SwitchPort\Status\Duplex + */ + public function getDuplex() { + return $this->duplex; + } + + /** + * @param string $duplex + * @see symbols\SwitchPort\Status\Duplex + */ + public function setDuplex( $duplex) { + $this->duplex = $duplex; + } + + /** + * @return int + * @see symbols\SwitchPort\Status\Speed + */ + public function getSpeed() { + return $this->speed; + } + + /** + * @param int $speed + * @see symbols\SwitchPort\Status\Speed + */ + public function setSpeed( $speed) { + $this->speed = $speed; + } + + /** + * @return string + */ + public function getMode() { + return $this->mode; + } + + /** + * @return array + */ + public function getMacList() { + return $this->mac_list; + } + +} diff --git a/freebox/api/v3/services/config/SwitchPort/Config.php b/freebox/api/v3/services/config/SwitchPort/Config.php new file mode 100644 index 0000000..af14634 --- /dev/null +++ b/freebox/api/v3/services/config/SwitchPort/Config.php @@ -0,0 +1,40 @@ +getAuthService( $service); + $rest->GET(); + + return new models\SwitchPort\Config( $rest->getCurlResponse()['result']); + } + + /** + * Update a port configuration + * @param \alphayax\freebox\api\v3\models\SwitchPort\Config $config + * @return \alphayax\freebox\api\v3\models\SwitchPort\Config + */ + public function update( models\SwitchPort\Config $config){ + $service = sprintf( static::API_SWITCH_PORT_CONFIG, $config->getId()); + $rest = $this->getAuthService( $service); + $rest->PUT( $config->toArray()); + + return new models\SwitchPort\Config( $rest->getCurlResponse()['result']); + } + +} diff --git a/freebox/api/v3/services/config/SwitchPort/Stats.php b/freebox/api/v3/services/config/SwitchPort/Stats.php new file mode 100644 index 0000000..58abdb0 --- /dev/null +++ b/freebox/api/v3/services/config/SwitchPort/Stats.php @@ -0,0 +1,27 @@ +getAuthService( $service); + $rest->GET(); + + return new models\SwitchPort\Stats( $rest->getCurlResponse()['result']); + } + +} diff --git a/freebox/api/v3/services/config/SwitchPort/Status.php b/freebox/api/v3/services/config/SwitchPort/Status.php new file mode 100644 index 0000000..c241aaf --- /dev/null +++ b/freebox/api/v3/services/config/SwitchPort/Status.php @@ -0,0 +1,25 @@ +getAuthService( self::API_SWITCH_STATUS); + $rest->GET(); + + return new models\SwitchPort\Status( $rest->getCurlResponse()['result']); + } + +} diff --git a/freebox/api/v3/symbols/SwitchPort/Config/Duplex.php b/freebox/api/v3/symbols/SwitchPort/Config/Duplex.php new file mode 100644 index 0000000..b705fff --- /dev/null +++ b/freebox/api/v3/symbols/SwitchPort/Config/Duplex.php @@ -0,0 +1,19 @@ +