當前位置: 首頁>>代碼示例>>Golang>>正文


Golang net.HardwareAddr類代碼示例

本文整理匯總了Golang中net.HardwareAddr的典型用法代碼示例。如果您正苦於以下問題:Golang HardwareAddr類的具體用法?Golang HardwareAddr怎麽用?Golang HardwareAddr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了HardwareAddr類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: disconnect

// Disconnects Switch dpid.
func disconnect(dpid net.HardwareAddr) {
	network.Lock()
	defer network.Unlock()
	log.Printf("Closing connection with: %s", dpid)
	network.Switches[dpid.String()].stream.Shutdown <- true
	delete(network.Switches, dpid.String())
}
開發者ID:postfix,項目名稱:ogo,代碼行數:8,代碼來源:switch.go

示例2: stringHardwareAddress

func stringHardwareAddress(hardwareAddr net.HardwareAddr) string {
	s := hardwareAddr.String()
	if len(s) == 0 {
		return "-"
	}
	return s
}
開發者ID:scraperwiki,項目名稱:nif,代碼行數:7,代碼來源:main.go

示例3: NewSwitch

// Builds and populates a Switch struct then starts listening
// for OpenFlow messages on conn.
func NewSwitch(stream *util.MessageStream, dpid net.HardwareAddr, app AppInterface) *OFSwitch {
	var s *OFSwitch

	if getSwitch(dpid) == nil {
		log.Infoln("Openflow Connection for new switch:", dpid)

		s = new(OFSwitch)
		s.app = app
		s.stream = stream
		s.dpid = dpid

		// Initialize the fgraph elements
		s.initFgraph()

		// Save it
		switchDb.Set(dpid.String(), s)

		// Main receive loop for the switch
		go s.receive()

	} else {
		log.Infoln("Openflow Connection for switch:", dpid)

		s = getSwitch(dpid)
		s.stream = stream
		s.dpid = dpid
	}

	// send Switch connected callback
	s.switchConnected()

	// Return the new switch
	return s
}
開發者ID:jojimt,項目名稱:netplugin,代碼行數:36,代碼來源:ofSwitch.go

示例4: getSwitch

// Returns a pointer to the Switch mapped to dpid.
func getSwitch(dpid net.HardwareAddr) *OFSwitch {
	sw, _ := switchDb.Get(dpid.String())
	if sw == nil {
		return nil
	}
	return sw.(*OFSwitch)
}
開發者ID:jojimt,項目名稱:netplugin,代碼行數:8,代碼來源:ofSwitch.go

示例5: GetLease

// GetLease : get an existing lease or mark a new one.
//  Find a  free address
// 1. unused
// 2. inactive
// 3. expired
// 4. fail
func (s Store) GetLease(mac net.HardwareAddr) (l *Lease, err error) {
	newl := &Lease{}
	// do I have a lease for this mac address
	logger.Debug("Find Lease for %v", mac)
	newl, err = s.leases.Mac(mac)
	if err == nil {
		return newl, err
	}
	logger.Debug("No existing lease %s ", err)
	// find a lease that is inactive and not reserved
	l, err = s.leases.Free(mac)
	if err != nil {
		logger.Debug("Lease search error %s ", err)
	} else {
		// get one lease and update it's mac address
		logger.Debug("found lease, updating")
		l.MAC = mac.String()
		l.Created = time.Now()
		if l.Name == "" {
			l.Name = fmt.Sprintf("node%d", l.ID)
		}
		logger.Debug("updated lease")
		s.leases.Save(s.DBname)
		return l, nil
	}

	return l, err
}
開發者ID:brianredbeard,項目名稱:astralboot,代碼行數:34,代碼來源:store.go

示例6: GetDevice

/**
 * Get device by MAC Address.
 */
func (this *devicehelper) GetDevice(macAddress net.HardwareAddr) (device Device, err error) {
	err = this.collection.GetObject(macAddress.String(), &device)
	if !bytes.Equal(device.MACAddress, macAddress) {
		device.MACAddress = macAddress
	}
	return
}
開發者ID:d2g,項目名稱:cloudpathway,代碼行數:10,代碼來源:device[helper].go

示例7: getHardwareAddrUint64

func getHardwareAddrUint64() uint64 {
	ifs, err := net.Interfaces()

	if err != nil {
		log.Fatalf("Could not get any network interfaces: %v, %+v", err, ifs)
	}

	var hwAddr net.HardwareAddr

	for _, i := range ifs {
		if len(i.HardwareAddr) > 0 {
			hwAddr = i.HardwareAddr
			break
		}
	}

	if hwAddr == nil {
		log.Fatalf("No interface found with a MAC address: %+v", ifs)
	}

	mac := hwAddr.String()
	hex := macStripRegexp.ReplaceAllLiteralString(mac, "")

	u, err := strconv.ParseUint(hex, 16, 64)

	if err != nil {
		log.Fatalf("Unable to parse %v (from mac %v) as an integer: %v", hex, mac, err)
	}

	return u
}
開發者ID:jmptrader,項目名稱:magical,代碼行數:31,代碼來源:magical.go

示例8: Switch

// Returns a pointer to the Switch mapped to dpid.
func Switch(dpid net.HardwareAddr) (*OFSwitch, bool) {
	network.RLock()
	defer network.RUnlock()
	if sw, ok := network.Switches[dpid.String()]; ok {
		return sw, ok
	}
	return nil, false
}
開發者ID:postfix,項目名稱:ogo,代碼行數:9,代碼來源:switch.go

示例9: Mac

//Mac return a lease for the given Hardwareaddr
func (ll LeaseList) Mac(mac net.HardwareAddr) (l *Lease, err error) {
	for _, i := range ll.Leases {
		if i.MAC == mac.String() {
			return i, nil
		}
	}
	return l, errors.New("no lease for mac")
}
開發者ID:brianredbeard,項目名稱:astralboot,代碼行數:9,代碼來源:leases.go

示例10: DeleteDevice

/**
 * Deletes a device with the given MAC address.
 */
func (this *devicehelper) DeleteDevice(macAddress net.HardwareAddr) error {
	err := this.collection.DeleteObject(macAddress.String())

	if err != nil {
		log.Println("Error Deleting Device from Datastore")
	}

	return err
}
開發者ID:d2g,項目名稱:cloudpathway,代碼行數:12,代碼來源:device[helper].go

示例11: Link

// Returns the link between Switch s and the Switch dpid.
func (s *OFSwitch) Link(dpid net.HardwareAddr) (l Link, ok bool) {
	s.linksMu.RLock()
	if n, k := s.links[dpid.String()]; k {
		l = *n
		ok = true
	}
	s.linksMu.RUnlock()
	return
}
開發者ID:postfix,項目名稱:ogo,代碼行數:10,代碼來源:switch.go

示例12: FindBoundIP

func (dt *DataTracker) FindBoundIP(mac net.HardwareAddr) *Subnet {
	for _, s := range dt.Subnets {
		for _, b := range s.Bindings {
			if b.Mac == mac.String() {
				return s
			}
		}
	}
	return nil
}
開發者ID:galthaus,項目名稱:ocb-dhcp,代碼行數:10,代碼來源:data.go

示例13: SetMacAddress

func (test *testEndpoint) SetMacAddress(mac net.HardwareAddr) error {
	if test.macAddress != "" {
		return types.ForbiddenErrorf("endpoint interface MAC address present (%s). Cannot be modified with %s.", test.macAddress, mac)
	}
	if mac == nil {
		return types.BadRequestErrorf("tried to set nil MAC address to endpoint interface")
	}
	test.macAddress = mac.String()
	return nil
}
開發者ID:YujiOshima,項目名稱:libnetwork,代碼行數:10,代碼來源:driver_test.go

示例14: GetLeaseByMacaddress

func (t *leasehelper) GetLeaseByMacaddress(hardwareAddress net.HardwareAddr) (databaseLease leasepool.Lease, err error) {
	var leaseip string
	err = t.macaddressKey.GetObject(hardwareAddress.String(), &leaseip)
	if err != nil {
		return
	}

	if leaseip != "" {
		return t.GetLeaseByIP(net.ParseIP(leaseip))
	}

	return
}
開發者ID:d2g,項目名稱:cloudpathway,代碼行數:13,代碼來源:lease[helper].go

示例15: GetMachine

// GetMachine returns a Machine interface which is the accessor/getter/setter
// for a node in the etcd datasource. If an entry associated with the passed
// mac address does not exist the second return value will be set to false
// part of GeneralDataSource interface implementation
func (ds *EtcdDataSource) GetMachine(mac net.HardwareAddr) (Machine, bool) {
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()

	machineName := nameFromMac(mac.String())
	response, err := ds.keysAPI.Get(ctx, ds.prefixify(path.Join("machines/"+machineName)), nil)
	if err != nil {
		return nil, false
	}
	if response.Node.Key[strings.LastIndex(response.Node.Key, "/")+1:] == machineName {
		return &EtcdMachine{mac, ds, ds.keysAPI}, true
	}
	return nil, false
}
開發者ID:colonelmo,項目名稱:blacksmith,代碼行數:18,代碼來源:etcd_datasource.go


注:本文中的net.HardwareAddr類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。