コード例 #1
0
ファイル: WelcomeController.php プロジェクト: junk0k/SGD
 public function path(RequestSave $request, $id)
 {
     if (Request::isMethod('post')) {
         $data = $request->all();
         foreach ($data['rows'] as $row) {
             if ($row['checkbox'] !== '0') {
                 $conn = new Connections();
                 $conn->connected_id = $id;
                 $conn->connection_id = $row['id'];
                 $conn->colour = $row['colour'];
                 $conn->bitrate = $row['bitrate'];
                 $conn->save();
             }
         }
     }
     $nodes = Node::get();
     $connect = Connections::get();
     return view('scripts.simulator.addpath')->with('nodes', $nodes)->with('conn', $connect)->with('self', Node::getById($id));
 }
コード例 #2
0
ファイル: Node.php プロジェクト: junk0k/SGD
 public static function getAll()
 {
     $conn = Connections::get();
     $nodes = self::get();
     $routers = array();
     foreach ($nodes as $key => $node) {
         $routers[$key]['node'] = $node;
         $amount = 0;
         foreach ($conn as $connection) {
             if ($connection->connected_id == $node->id) {
                 $amount++;
             }
         }
         $routers[$key]['connections'] = $amount;
     }
     return $routers;
 }
コード例 #3
0
ファイル: Node.php プロジェクト: Namiastek/SGD
 public static function getAll()
 {
     $conn = Connections::get();
     $nodes = self::get();
     $routers = array();
     foreach ($nodes as $key => $node) {
         $routers[$key]['node'] = $node;
         $from = $to = 0;
         foreach ($conn as $connection) {
             if ($connection->connected_id == $node->id) {
                 $from++;
             }
             if ($connection->connection_id == $node->id) {
                 $to++;
             }
         }
         $routers[$key]['connections'] = $from;
         $routers[$key]['connections_to'] = $to;
     }
     return $routers;
 }
コード例 #4
0
ファイル: ConfigController.php プロジェクト: Namiastek/SGD
 public function createConfig($id)
 {
     $node = Node::find($id);
     $loIP = $node['name'];
     $connIP = $node['ip'];
     $config = 'interface bridge add name="lo-bridge"; ip address add address=' . $loIP . ' interface=lo-bridge; ';
     $config .= 'routing ospf network add area=backbone network=' . $node['name'] . '; ';
     $connected = Connections::where('connected_id', $id)->get();
     foreach ($connected as $key => $connection) {
         $interface[$key] = $connection['interface1'];
         $bitrate[$key] = $connection['bitrate'];
         $network[$key] = $connection['network'];
         $colour[$key] = $connection['colour'];
         $test = explode('.', $network[$key]);
         $mask = substr(strrchr($test[3], '/'), 1);
         $netIP = $test[0] . '.' . $test[1] . '.' . $test[2] . '.' . '1' . '/' . $mask;
         // dorobic potem kolory, bitrate
         $config .= 'ip address add address=' . $netIP . ' interface=' . $interface[$key] . '; ';
         $config .= 'routing ospf network add area=backbone network=' . $network[$key] . '; ';
         $config .= 'mpls ldp interface add interface=' . $interface[$key] . '; ';
         // Traffic Eng
         $config .= 'mpls traffic-eng interface add interface=' . $interface[$key] . ' bandwidth=' . $bitrate[$key] . 'M ';
         if ($colour[$key] == 'yellow') {
             $config .= 'resource-class=1; ';
         } elseif ($colour[$key] == 'green') {
             $config .= 'resource-class=2; ';
         } elseif ($colour[$key] == 'grey') {
             $config .= 'resource-class=4; ';
         } elseif ($colour[$key] == 'red') {
             $config .= 'resource-class=8; ';
         }
     }
     $connect = Connections::where('connection_id', $id)->get();
     foreach ($connect as $key => $connection) {
         $interface[$key] = $connection['interface2'];
         $bitrate[$key] = $connection['bitrate'];
         $network[$key] = $connection['network'];
         $colour[$key] = $connection['colour'];
         $test = explode('.', $network[$key]);
         $mask = substr(strrchr($test[3], '/'), 1);
         $netIP = $test[0] . '.' . $test[1] . '.' . $test[2] . '.' . '2' . '/' . $mask;
         $config .= 'ip address add address=' . $netIP . ' interface=' . $interface[$key] . '; ';
         $config .= 'routing ospf network add area=backbone network=' . $network[$key] . '; ';
         $config .= 'mpls ldp interface add interface=' . $interface[$key] . '; ';
         // Traffic Eng
         $config .= 'mpls traffic-eng interface add interface=' . $interface[$key] . ' bandwidth=' . $bitrate[$key] . 'M ';
         if ($colour[$key] == 'yellow') {
             $config .= 'resource-class=1; ';
         } elseif ($colour[$key] == 'green') {
             $config .= 'resource-class=2; ';
         } elseif ($colour[$key] == 'grey') {
             $config .= 'resource-class=4; ';
         } elseif ($colour[$key] == 'red') {
             $config .= 'resource-class=8; ';
         }
     }
     $config .= 'routing ospf instance set default mpls-te-area=backbone mpls-te-router-id=lo-bridge distribute-default=never redistribute-connected=as-type-1 router-id=' . $node['name'] . '; ';
     //MPLS
     $config .= 'mpls ldp set enabled=yes lsr-id=' . $node['name'] . ' transport-address=' . $node['name'] . '; ';
     // Traffic Eng
     $config .= 'mpls traffic-eng tunnel-path add use-cspf=yes name=dyn; ';
     return $config;
 }