func sendLLDP(deviceID string, f openflow.Factory, w trans.Writer, p openflow.Port) error { lldp, err := newLLDPEtherFrame(deviceID, p) if err != nil { return err } outPort := openflow.NewOutPort() outPort.SetValue(p.Number()) // Packet out to the port action, err := f.NewAction() if err != nil { return err } action.SetOutPort(outPort) out, err := f.NewPacketOut() if err != nil { return err } // From controller out.SetInPort(openflow.NewInPort()) out.SetAction(action) out.SetData(lldp) return w.Write(out) }
func newLLDPEtherFrame(deviceID string, port openflow.Port) ([]byte, error) { lldp := &protocol.LLDP{ ChassisID: protocol.LLDPChassisID{ SubType: 7, // Locally assigned alpha-numeric string Data: []byte(deviceID), }, PortID: protocol.LLDPPortID{ SubType: 5, // Interface Name Data: []byte(fmt.Sprintf("cherry/%v", port.Number())), }, TTL: 120, } payload, err := lldp.MarshalBinary() if err != nil { return nil, err } ethernet := &protocol.Ethernet{ SrcMAC: port.MAC(), // LLDP multicast MAC address DstMAC: []byte{0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E}, // LLDP ethertype Type: 0x88CC, Payload: payload, } frame, err := ethernet.MarshalBinary() if err != nil { return nil, err } return frame, nil }