本文整理汇总了Golang中net.HardwareAddr.String方法的典型用法代码示例。如果您正苦于以下问题:Golang HardwareAddr.String方法的具体用法?Golang HardwareAddr.String怎么用?Golang HardwareAddr.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.HardwareAddr
的用法示例。
在下文中一共展示了HardwareAddr.String方法的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())
}
示例2: stringHardwareAddress
func stringHardwareAddress(hardwareAddr net.HardwareAddr) string {
s := hardwareAddr.String()
if len(s) == 0 {
return "-"
}
return s
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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")
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}