Пример #1
0
func (b *DemoInstance) PacketIn(dpid net.HardwareAddr, pkt *ofp10.PacketIn) {
	eth := pkt.Data
	// Ignore link discovery packet types.
	if eth.Ethertype == 0xa0f1 || eth.Ethertype == 0x88cc {
		return
	}

	b.SetHost(eth.HWSrc, pkt.InPort)
	if host, ok := b.Host(eth.HWDst); ok {
		f1 := ofp10.NewFlowMod()
		f1.Match.DLSrc = eth.HWSrc
		f1.Match.DLDst = eth.HWDst
		f1.AddAction(ofp10.NewActionOutput(host.port))
		f1.IdleTimeout = 3

		f2 := ofp10.NewFlowMod()
		f2.Match.DLSrc = eth.HWDst
		f2.Match.DLDst = eth.HWSrc
		f2.AddAction(ofp10.NewActionOutput(pkt.InPort))
		f2.IdleTimeout = 3

		if s, ok := ogo.Switch(dpid); ok {
			s.Send(f1)
			s.Send(f2)
		}
	} else {
		p := ofp10.NewPacketOut()
		p.InPort = pkt.InPort
		p.AddAction(ofp10.NewActionOutput(ofp10.P_ALL))
		p.Data = &eth
		if sw, ok := ogo.Switch(dpid); ok {
			sw.Send(p)
		}
	}
}
Пример #2
0
func (o *OgoInstance) linkDiscoveryLoop(dpid net.HardwareAddr) {
	for {
		select {
		case <-o.shutdown:
			return
		// Every two seconds send a link discovery packet.
		case <-time.After(time.Second * 2):
			e := eth.New()
			e.Ethertype = 0xa0f1
			e.HWSrc = dpid[2:]
			linkDsc := NewLinkDiscovery()
			linkDsc.SrcDPID = dpid
			e.Data = linkDsc

			pkt := ofp10.NewPacketOut()
			pkt.Data = e
			pkt.AddAction(ofp10.NewActionOutput(ofp10.P_ALL))

			if sw, ok := Switch(dpid); ok {
				sw.Send(pkt)
			}
		}
	}
}