Exemple #1
0
func (b *DemoApplication) parsePacketIn(dpid string, pkt *ofp10.OfpPacketIn) {
	eth := pkt.Data
	hwSrc := eth.HWSrc.String()
	hwDst := eth.HWDst.String()
	if _, ok := b.hostMap[hwSrc]; !ok {
		b.hostMap[hwSrc] = pkt.InPort
	}
	if _, ok := b.hostMap[hwDst]; ok {
		f1 := ofp10.NewFlowMod()
		act1 := ofp10.NewActionOutput()
		act1.Port = b.hostMap[hwDst]
		f1.Actions = append(f1.Actions, act1)
		m1 := ofp10.NewMatch()
		m1.DLSrc = eth.HWSrc
		m1.DLDst = eth.HWDst
		f1.Match = *m1
		f1.IdleTimeout = 3

		f2 := ofp10.NewFlowMod()
		act2 := ofp10.NewActionOutput()
		act2.Port = b.hostMap[hwSrc]
		f2.Actions = append(f1.Actions, act2)
		m2 := ofp10.NewMatch()
		m2.DLSrc = eth.HWDst
		m2.DLDst = eth.HWSrc
		f2.Match = *m2
		f2.IdleTimeout = 3
		if s, ok := ogo.GetSwitch(dpid); ok {
			s.Send(f1)
			s.Send(f2)
		}
	} else {
		// Flood
		pktOut := ofp10.NewPacketOut()
		pktOut.Actions = append(pktOut.Actions, ofp10.NewActionOutput())
		pktOut.Data = &pkt.Data
		if s, ok := ogo.GetSwitch(dpid); ok {
			s.Send(pktOut)
		}
	}
}
Exemple #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):
			eth := pacit.NewEthernet()
			eth.Ethertype = 0xa0f1
			eth.HWSrc = dpid[2:]
			eth.Data = NewLinkDiscovery(dpid)

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

			if sw, ok := Switch(dpid); ok {
				sw.Send(pkt)
			}
		}
	}
}
Exemple #3
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 {
		fmt.Println(eth.HWSrc, ":", pkt.InPort, "to", eth.HWDst, ":", host.port)
		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 := core.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 := core.Switch(dpid); ok {
			sw.Send(p)
		}
	}
}