当前位置: 首页>>代码示例>>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;未经允许,请勿转载。