本文整理汇总了PHP中Host::setTypeByMAC方法的典型用法代码示例。如果您正苦于以下问题:PHP Host::setTypeByMAC方法的具体用法?PHP Host::setTypeByMAC怎么用?PHP Host::setTypeByMAC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host::setTypeByMAC方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionListHosts
public function actionListHosts()
{
$this->layout = '//layouts/json';
try {
if (isset($_GET['hostId'])) {
$hostId = (int) $_GET['hostId'];
// get root host
//
$rootHost = $hosts[] = Host::model()->findbyPk($hostId);
// get connections
$hostConnections = $rootHost->getConnections();
// get host from connections
foreach ($hostConnections as $hosts_conn) {
array_push($hosts, $hosts_conn->hostDst);
}
// in switches, get hosts by CAM table
if ($rootHost->type == Host::TYPE_SWITCH) {
$rootHost->loadCamTable();
// TODO: associar roteadores aos switches para pegar a
// tabela ARP dos gateways da rede
//
$gateway = Host::model()->findByPk(Yii::app()->params['hostGatewayId']);
// $arpTable = array();
foreach ($rootHost->cam_table as $k => $camHost) {
// se existir conexao cadastrada para a porta, ignore o host
// TODO: usar tipo do link==backbone
$hostOnPort = $rootHost->getHostOnPort($camHost['port']);
if ($hostOnPort instanceof Host && $hostOnPort->type != Host::TYPE_UNKNOWN) {
continue;
}
// havendo 2 ou + hosts numa porta sem conexao cadastrada, criar 'hub virtual'
$port = $camHost['port'];
$portLabelPrefix = 'port_';
if ($port == $rootHost->cam_table[$k + 1]['port'] || $sourcePort == $portLabelPrefix . $port) {
$sourcePort = $portLabelPrefix . $port;
if (!isset($virtualHost[$sourcePort])) {
$virtualHost[$sourcePort] = new Host();
$virtualHost[$sourcePort]->name = $sourcePort;
$virtualHost[$sourcePort]->type = Host::TYPE_SUPPOSED_HUB;
array_push($hosts, $virtualHost[$sourcePort]);
$virtualConn[$sourcePort] = new Connection();
$virtualConn[$sourcePort]->hostSrc = $rootHost;
$virtualConn[$sourcePort]->hostDst = $virtualHost[$sourcePort];
$virtualConn[$sourcePort]->host_src_port = $camHost['port'];
$virtualConn[$sourcePort]->type = Connection::TYPE_SUPPOSED_LINK;
// TODO: especificar tipo do link
array_push($hostConnections, $virtualConn[$sourcePort]);
}
} else {
unset($sourcePort);
}
// host
$host = Host::model()->findByAttributes(array('mac' => $camHost['mac']));
if ($host instanceof Host) {
$h = $host;
} else {
$h = new Host();
$h->mac = $camHost['mac'];
$h->ip = $gateway instanceof Host ? $gateway->getIpInArpTable($camHost['mac']) : null;
$h->name = $h->ip ? $h->ip : $h->mac;
$h->setTypeByMAC();
}
array_push($hosts, $h);
// connection
$c = new Connection();
$c->hostSrc = $virtualHost[$sourcePort] ? $virtualHost[$sourcePort] : $rootHost;
$c->hostDst = $h;
$c->host_src_port = $camHost['port'];
$c->type = Connection::TYPE_UNKNOWN;
// vlan
$c->vlan = Vlan::model()->findByAttributes(array('tag' => $camHost['vlan_tag']));
if (!$c->vlan instanceof Vlan) {
$c->vlan = new Vlan();
$c->vlan->tag = $camHost['vlan_tag'];
}
array_push($hostConnections, $c);
}
}
} else {
$hosts = Host::model()->findAll(array('order' => 'id'));
$hostConnections = Connection::model()->findAll();
}
$this->render('listHosts', array('hosts' => $hosts, 'hostConnections' => $hostConnections));
} catch (Exception $exc) {
$this->render('error', array('error' => "listHosts error:" . $exc->getMessage()));
}
}