public function path(RequestSave $request, $id) { if (Request::isMethod('post')) { $data = $request->all(); //dd($data['rows']); Connections::where('connected_id', $id)->delete(); foreach ($data['rows'] as $key => $row) { if ($row['checkbox'][$row['id']] !== '0') { $conn = new Connections(); $conn->connected_id = $id; $conn->connection_id = $row['id']; $conn->colour = $row['colour']; $conn->network = $row['network']; $conn->interface1 = $row['interface1']; $conn->interface2 = $row['interface2']; $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)); }
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; }