• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ipc.Mk_chmsg函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/att/gopkgs/ipc.Mk_chmsg函数的典型用法代码示例。如果您正苦于以下问题:Golang Mk_chmsg函数的具体用法?Golang Mk_chmsg怎么用?Golang Mk_chmsg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Mk_chmsg函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: mirror_delete

/*
 * Handle a DELETE /tegu/mirrors/<name>/[?cookie=<cookie>] request.
 */
func mirror_delete(in *http.Request, out http.ResponseWriter, data []byte) (code int, msg string) {
	name, cookie := getNameAndCookie(in)
	mirror := lookupMirror(name, cookie)
	if mirror == nil {
		code = http.StatusNotFound
		msg = "Not found."
		return
	}
	if !mirror.Is_valid_cookie(&cookie) {
		code = http.StatusUnauthorized
		msg = "Unauthorized."
		return
	}

	req := ipc.Mk_chmsg()
	my_ch := make(chan *ipc.Chmsg) // allocate channel for responses to our requests
	defer close(my_ch)             // close it on return
	namepluscookie := []*string{&name, &cookie}
	req.Send_req(rmgr_ch, my_ch, REQ_DEL, namepluscookie, nil) // remove the reservation
	req = <-my_ch                                              // wait for completion

	if req.State == nil {
		ckptreq := ipc.Mk_chmsg()
		ckptreq.Send_req(rmgr_ch, nil, REQ_CHKPT, nil, nil) // request a chkpt now, but don't wait on it
	}

	code = http.StatusNoContent
	msg = ""
	return
}
开发者ID:krjoshi,项目名称:tegu,代码行数:33,代码来源:http_mirror_api.go


示例2: send_pt_fmods

/*
	Send a passthrough flowmod generation request to the agent manager.
	This is basically taking the struct that the reservation manager
	filled in and converting it to a map.

	Send a bandwidth endpoint flow-mod request to the agent manager.
	This is little more than a wrapper that converts the fq_req into
	an agent request. The ultimate agent action is to put in all
	needed flow-mods on an endpoint host in one go, so no need for
	individual requests for each and no need for tegu to understand
	the acutal flow-mod mechanics any more.

	Yes, this probably _could_ be pushed up into the reservation manager
	and sent from there to the agent manager, but for now, since the
	ip2mac information is local to fq-mgr, we'll keep it here.  (That
	info is local to fq-mgr b/c in the original Tegu it came straight
	in from skoogi and it was fq-mgr's job to interface with skoogi.)
*/
func send_pt_fmods(data *Fq_req, ip2mac map[string]*string, phost_suffix *string) {

	if *data.Swid == "" { // we must have a switch name to set bandwidth fmods
		fq_sheep.Baa(1, "unable to send passthrough fmod request to agent: no switch defined in input data")
		return
	}

	host := data.Swid
	if phost_suffix != nil { // we need to add the physical host suffix
		host = add_phost_suffix(host, phost_suffix)
	}

	if data.Match.Smac != nil { // caller can pass in IP and we'll convert it
		if ip2mac[*data.Match.Smac] != nil {
			data.Match.Smac = ip2mac[*data.Match.Smac] // res-mgr thinks in IP, flow-mods need mac; convert
		}
	}

	msg := &agent_cmd{Ctype: "action_list"}  // create a message for agent manager to send to an agent
	msg.Actions = make([]action, 1)          // just a single action
	msg.Actions[0].Atype = "passthru"        // set all related passthrough flow-mods
	msg.Actions[0].Hosts = make([]string, 1) // passthrough flow-mods created on just one host
	msg.Actions[0].Hosts[0] = *host
	msg.Actions[0].Data = data.To_pt_map() // convert useful data from caller into parms for agent

	json, err := json.Marshal(msg) // bundle into a json string
	if err != nil {
		fq_sheep.Baa(0, "unable to build json to set passthrough flow-mods")
	} else {
		tmsg := ipc.Mk_chmsg()
		tmsg.Send_req(am_ch, nil, REQ_SENDSHORT, string(json), nil) // send as a short request to one agent
	}

	fq_sheep.Baa(2, "passthru flow-mod request sent to agent manager: %s", json)
}
开发者ID:prydeep,项目名称:tegu,代码行数:53,代码来源:fq_pass.go


示例3: send_bw_fmods

/*
	Send a bandwidth endpoint flow-mod request to the agent manager.
	This is little more than a wrapper that converts the fq_req into
	an agent request. The ultimate agent action is to put in all
	needed flow-mods on an endpoint host in one go, so no need for
	individual requests for each and no need for tegu to understand
	the acutal flow-mod mechanics any more.

	Yes, this probably _could_ be pushed up into the reservation manager
	and sent from there to the agent manager, but for now, since the
	ip2mac information is local to fq-mgr, we'll keep it here.  (That
	info is local to fq-mgr b/c in the original Tegu it came straight
	in from skoogi and it was fq-mgr's job to interface with skoogi.)
*/
func send_bw_fmods(data *Fq_req, ip2mac map[string]*string, phost_suffix *string) {

	if data.Espq.Switch == "" { // we must have a switch name to set bandwidth fmods
		fq_sheep.Baa(1, "unable to send bw-fmods request to agent: no switch defined in input data")
		return
	}

	host := &data.Espq.Switch // Espq.Switch has real name (host) of switch
	if phost_suffix != nil {  // we need to add the physical host suffix
		host = add_phost_suffix(host, phost_suffix)
	}

	data.Match.Smac = ip2mac[*data.Match.Ip1] // res-mgr thinks in IP, flow-mods need mac; convert
	data.Match.Dmac = ip2mac[*data.Match.Ip2] // add to data for To_bw_map() call later

	msg := &agent_cmd{Ctype: "action_list"}  // create a message for agent manager to send to an agent
	msg.Actions = make([]action, 1)          // just a single action
	msg.Actions[0].Atype = "bw_fmod"         // set all related bandwidth flow-mods for an endpoint
	msg.Actions[0].Hosts = make([]string, 1) // bw endpoint flow-mods created on just one host
	msg.Actions[0].Hosts[0] = *host
	msg.Actions[0].Data = data.To_bw_map() // convert useful data from caller into parms for agent

	json, err := json.Marshal(msg) // bundle into a json string
	if err != nil {
		fq_sheep.Baa(0, "unable to build json to set flow mod")
	} else {
		tmsg := ipc.Mk_chmsg()
		tmsg.Send_req(am_ch, nil, REQ_SENDSHORT, string(json), nil) // send as a short request to one agent
	}

	fq_sheep.Baa(2, "bandwidth endpoint flow-mod request sent to agent manager: %s", json)

}
开发者ID:robert-eby,项目名称:tegu,代码行数:47,代码来源:fq_mgr.go


示例4: Del_res

/*
	Looks for the named reservation and deletes it if found. The cookie must be either the
	supper cookie, or the cookie that the user supplied when the reservation was created.
	Deletion is affected by resetting the expiry time on the pledge to now + a few seconds.
	This will cause a new set of flow-mods to be sent out with an expiry time that will
	take them out post haste and without the need to send "delete" flow-mods out.

	This function sends a request to the network manager to delete the related queues. This
	must be done here so as to prevent any issues with the loosely coupled management of
	reservation and queue settings.  It is VERY IMPORTANT to delete the reservation from
	the network perspective BEFORE the expiry time is reset.  If it is reset first then
	the network splits timeslices based on the new expiry and queues end up dangling.
*/
func (inv *Inventory) Del_res(name *string, cookie *string) (state error) {

	gp, state := inv.Get_res(name, cookie)
	if gp != nil {
		rm_sheep.Baa(2, "resgmgr: deleted reservation: %s", (*gp).To_str())
		state = nil

		switch p := (*gp).(type) {
		case *gizmos.Pledge_mirror:
			p.Set_expiry(time.Now().Unix()) // expire the mirror NOW
			p.Set_pushed()                  // need this to force undo to occur

		case *gizmos.Pledge_bw, *gizmos.Pledge_bwow: // network handles either type
			ch := make(chan *ipc.Chmsg) // do not close -- senders close channels
			req := ipc.Mk_chmsg()
			req.Send_req(nw_ch, ch, REQ_DEL, p, nil) // delete from the network point of view
			req = <-ch                               // wait for response from network
			state = req.State
			p.Set_expiry(time.Now().Unix() + 15) // set the expiry to 15s from now which will force it out
			(*gp).Reset_pushed()                 // force push of flow-mods that reset the expiry

		case *gizmos.Pledge_pass:
			p.Set_expiry(time.Now().Unix() + 15) // set the expiry to 15s from now which will force it out
			(*gp).Reset_pushed()                 // force push of flow-mods that reset the expiry
		}
	} else {
		rm_sheep.Baa(2, "resgmgr: unable to delete reservation: not found: %s", *name)
	}

	return
}
开发者ID:dhanunjaya,项目名称:tegu,代码行数:44,代码来源:res_mgr.go


示例5: undo_mirror_reservation

/*
 *	Push a "delete mirror" request out to an agent in order to remove the mirror.
 */
func undo_mirror_reservation(gp *gizmos.Pledge, rname string, ch chan *ipc.Chmsg) {

	p, ok := (*gp).(*gizmos.Pledge_mirror) // better be a mirroring pledge
	if !ok {
		rm_sheep.Baa(1, "internal error: pledge passed to undo_mirror_reservations wasn't a mirror pledge")
		(*gp).Set_pushed() // prevent looping until it expires
		return
	}

	id := p.Get_id()
	// This is somewhat of a hack, but as long as the code in tegu_agent:do_mirrorwiz doesn't change, it should work
	arg := *id
	opts := p.Get_Options()
	if opts != nil && *opts != "" {
		arg = fmt.Sprintf("-o%s %s", *opts, *id)
	}

	host := p.Get_qid()
	rm_sheep.Baa(1, "Deleting mirror %s on host %s", *id, *host)
	json := `{ "ctype": "action_list", "actions": [ { `
	json += `"atype": "mirrorwiz", `
	json += fmt.Sprintf(`"hosts": [ %q ], `, *host)
	json += fmt.Sprintf(`"qdata": [ "del", %q ] `, arg)
	json += `} ] }`
	rm_sheep.Baa(2, " JSON -> %s", json)
	msg := ipc.Mk_chmsg()
	msg.Send_req(am_ch, nil, REQ_SENDSHORT, json, nil) // send this as a short request to one agent
	p.Set_pushed()
}
开发者ID:prydeep,项目名称:tegu,代码行数:32,代码来源:res_mgr_mirror.go


示例6: phosts_changed

/*
	Check the two pledges (old, new) to see if the related physical hosts have moved.
	Returns true if the physical hosts have changed. We get the current physical location
	for the hosts from the network based on the new pledge, and look at the path of the
	old pledge to see if they are the same as what was captured in the original path.
	We return true if they are different.
*/
func phosts_changed( old *gizmos.Pledge, new *gizmos.Pledge ) ( bool ) {

	var (
		p2 *string = nil	
	)

	if old == nil || new == nil {
		return false
	}

	a1, a2 := (*new).Get_hosts( )							// get hosts from the new pledge
	ch := make( chan *ipc.Chmsg )						// do not close -- senders close channels
	req := ipc.Mk_chmsg( )
	req.Send_req( nw_ch, ch, REQ_GETPHOST, a1, nil )	// xlate hostnames to physical host location
	req = <- ch											// wait for response from network
	p1 := req.Response_data.( *string )

	if a2 != nil {
		if len( *a2) > 1  &&  (*a2)[0:1] != "!" {				// !// names aren't known, don't map
			req.Send_req( nw_ch, ch, REQ_GETPHOST, a2, nil )
			req = <- ch									
			if req.Response_data != nil {					// for an external address this will be unknown
				p2 = req.Response_data.( *string )
			}
		}
	}

	return (*old).Same_anchors( p1, p2 )
}
开发者ID:att,项目名称:tegu,代码行数:36,代码来源:res_mgr.go


示例7: adjust_queues_agent

/*
	Builds one setqueue json request per host and sends it to the agent. If there are
	multiple agents attached, the individual messages will be fanned out across the
	available agents, otherwise the agent will just process them sequentially which
	would be the case if we put all hosts into the same message.

	This now augments the switch name with the suffix; needs to be fixed for q-full
	so that it handles intermediate names properly.

	In the world with the ssh-broker, there is no -h host on the command line and
	the script's view of host name might not have the suffix that we are supplied
	with.  To prevent the script from not recognising an entry, we must now
	put an entry for both the host name and hostname+suffix into the list.
*/
func adjust_queues_agent(qlist []string, hlist *string, phsuffix *string) {
	var (
		qjson     string // final full json blob
		qjson_pfx string // static prefix
		sep       = ""
	)

	target_hosts := make(map[string]bool) // hosts that are actually affected by the queue list
	if phsuffix != nil {                  // need to convert the host names in the list to have suffix
		nql := make([]string, len(qlist)*2) // need one for each possible host name

		offset := len(qlist) // put the originals into the second half of the array
		for i := range qlist {
			nql[offset+i] = qlist[i] // just copy the original

			toks := strings.SplitN(qlist[i], "/", 2) // split host from front
			if len(toks) == 2 {
				nh := add_phost_suffix(&toks[0], phsuffix) // add the suffix
				nql[i] = *nh + "/" + toks[1]
				target_hosts[*nh] = true
			} else {
				nql[i] = qlist[i]
				fq_sheep.Baa(1, "target host not snarfed: %s", qlist[i])
			}
		}

		qlist = nql
	} else { // just snarf the list of hosts affected
		for i := range qlist {
			toks := strings.SplitN(qlist[i], "/", 2) // split host from front
			if len(toks) == 2 {
				target_hosts[toks[0]] = true
			}
		}
	}

	fq_sheep.Baa(1, "adjusting queues:  sending %d queue setting items to agents", len(qlist))

	qjson_pfx = `{ "ctype": "action_list", "actions": [ { "atype": "setqueues", "qdata": [ `

	for i := range qlist {
		fq_sheep.Baa(2, "queue info: %s", qlist[i])
		qjson_pfx += fmt.Sprintf("%s%q", sep, qlist[i])
		sep = ", "
	}

	qjson_pfx += ` ], "hosts": [ `

	sep = ""
	for h := range target_hosts { // build one request per host and send to agents -- multiple ageents then these will fan out
		qjson = qjson_pfx // seed the next request with the constant prefix
		qjson += fmt.Sprintf("%s%q", sep, h)

		qjson += ` ] } ] }`

		fq_sheep.Baa(2, "queue update: host=%s %s", h, qjson)
		tmsg := ipc.Mk_chmsg()
		tmsg.Send_req(am_ch, nil, REQ_SENDSHORT, qjson, nil) // send this as a short request to one agent
	}
}
开发者ID:robert-eby,项目名称:tegu,代码行数:74,代码来源:fq_mgr.go


示例8: push_mirror_reservation

/*
 *	Push an "add mirror" request out to an agent in order to create the mirror.
 */
func push_mirror_reservation(gp *gizmos.Pledge, rname string, ch chan *ipc.Chmsg) {

	p, ok := (*gp).(*gizmos.Pledge_mirror) // better be a mirroring pledge
	if !ok {
		rm_sheep.Baa(1, "internal error: pledge passed to push_mirror_reservations wasn't a mirror pledge")
		(*gp).Set_pushed() // prevent looping until it expires
		return
	}

	ports, out, _, _, _, _, _, _ := p.Get_values()
	ports2 := strings.Replace(*ports, " ", ",", -1) // ports must be comma separated
	id := p.Get_id()
	host := p.Get_qid()
	rm_sheep.Baa(1, "Adding mirror %s on host %s", *id, *host)
	json := `{ "ctype": "action_list", "actions": [ { `
	json += `"atype": "mirrorwiz", `
	json += fmt.Sprintf(`"hosts": [ %q ], `, *host)
	if strings.Contains(ports2, ",vlan:") {
		// Because we have to store the ports list and the vlans in the same field
		// we split it out here
		n := strings.Index(ports2, ",vlan:")
		vlan := ports2[n+6:]
		ports2 = ports2[:n]
		json += fmt.Sprintf(`"qdata": [ "add", %q, %q, %q, %q ] `, *id, ports2, *out, vlan)
	} else {
		json += fmt.Sprintf(`"qdata": [ "add", %q, %q, %q ] `, *id, ports2, *out)
	}
	json += `} ] }`
	rm_sheep.Baa(2, " JSON -> %s", json)
	msg := ipc.Mk_chmsg()
	msg.Send_req(am_ch, nil, REQ_SENDSHORT, json, nil) // send this as a short request to one agent
	p.Set_pushed()
}
开发者ID:robert-eby,项目名称:tegu,代码行数:36,代码来源:res_mgr_mirror.go


示例9: validatePort

/*
 * Validate a port.
 */
func validatePort(port *string) (vm *Net_vm, err error) {
	// handle mac:port form
	if strings.HasPrefix(*port, "mac:") {
		// Map the port MAC to a phost
		mac := (*port)[4:]

		my_ch := make(chan *ipc.Chmsg)
		defer close(my_ch)

		req := ipc.Mk_chmsg()
		req.Send_req(nw_ch, my_ch, REQ_GET_PHOST_FROM_MAC, &mac, nil) // request MAC -> phost translation
		req = <-my_ch
		if req.Response_data == nil {
			err = fmt.Errorf("Cannot find MAC: " + mac)
		} else {
			vm = Mk_netreq_vm(nil, nil, nil, nil, req.Response_data.(*string), &mac, nil, nil, nil) // only use the two fields
			http_sheep.Baa(1, "name=NIL id=NIL ip4=NIL phost=%s mac=%s gw=NIL fip=NIL", safe(vm.phost), safe(vm.mac))
		}
		return
	}

	// handle project/host form
	my_ch := make(chan *ipc.Chmsg) // allocate channel for responses to our requests
	defer close(my_ch)

	req := ipc.Mk_chmsg()
	req.Send_req(osif_ch, my_ch, REQ_GET_HOSTINFO, port, nil) // request data
	req = <-my_ch
	if req.Response_data != nil {
		vm = req.Response_data.(*Net_vm)
		if vm.phost == nil {
			// There seems to be a bug in REQ_GET_HOSTINFO, such that the 2nd call works
			// wanting to capture this more aggressively since I cannot reproduce the first time failure
			http_sheep.Baa(1, "requiring a second osif lazy call: port=%s name=%s id=%s ip4=%s phost=%s mac=%s gw=%s fip=%s", safe(port), safe(vm.name), safe(vm.id), safe(vm.ip4), safe(vm.phost), safe(vm.mac), safe(vm.gw), safe(vm.fip))
			req.Send_req(osif_ch, my_ch, REQ_GET_HOSTINFO, port, nil)
			req = <-my_ch
			vm = req.Response_data.(*Net_vm)
			err = req.State
		}
		http_sheep.Baa(1, "name=%s id=%s ip4=%s phost=%s mac=%s gw=%s fip=%s", safe(vm.name), safe(vm.id), safe(vm.ip4), safe(vm.phost), safe(vm.mac), safe(vm.gw), safe(vm.fip))
	} else {
		if req.State != nil {
			err = req.State
		}
	}
	return
}
开发者ID:krjoshi,项目名称:tegu,代码行数:50,代码来源:http_mirror_api.go


示例10: process_input

/*
	Deal with incoming data from an agent. We add the buffer to the cahce
	(all input is expected to be json) and attempt to pull a blob of json
	from the cache. If the blob is pulled, then we act on it, else we
	assume another buffer or more will be coming to complete the blob
	and we'll do it next time round.
*/
func (a *agent) process_input(buf []byte) {
	var (
		req agent_msg // unpacked message struct
	)

	a.jcache.Add_bytes(buf)
	jblob := a.jcache.Get_blob() // get next blob if ready
	for jblob != nil {
		err := json.Unmarshal(jblob, &req) // unpack the json

		if err != nil {
			am_sheep.Baa(0, "ERR: unable to unpack agent_message: %s  [TGUAGT000]", err)
			am_sheep.Baa(2, "offending json: %s", string(buf))
		} else {
			am_sheep.Baa(1, "%s/%s received from agent", req.Ctype, req.Rtype)

			switch req.Ctype { // "command type"
			case "response": // response to a request
				if req.State == 0 {
					switch req.Rtype {
					case "map_mac2phost":
						msg := ipc.Mk_chmsg()
						msg.Send_req(nw_ch, nil, REQ_MAC2PHOST, req.Rdata, nil) // send into network manager -- we don't expect response

					default:
						am_sheep.Baa(2, "WRN:  success response data from agent was ignored for: %s  [TGUAGT001]", req.Rtype)
						if am_sheep.Would_baa(2) {
							am_sheep.Baa(2, "first few ignored messages from response:")
							for i := 0; i < len(req.Rdata) && i < 10; i++ {
								am_sheep.Baa(2, "[%d] %s", i, req.Rdata[i])
							}
						}
					}
				} else {
					switch req.Rtype {
					case "bwow_fmod":
						am_sheep.Baa(1, "ERR: oneway bandwidth flow-mod failed; check agent logs for details  [TGUAGT006]")
						for i := 0; i < len(req.Rdata) && i < 20; i++ {
							am_sheep.Baa(1, "  [%d] %s", i, req.Rdata[i])
						}

					default:
						am_sheep.Baa(1, "WRN: response messages for failed command were not interpreted: %s  [TGUAGT002]", req.Rtype)
						for i := 0; i < len(req.Rdata) && i < 20; i++ {
							am_sheep.Baa(2, "  [%d] %s", i, req.Rdata[i])
						}
					}
				}

			default:
				am_sheep.Baa(1, "WRN:  unrecognised command type type from agent: %s  [TGUAGT003]", req.Ctype)
			}
		}

		jblob = a.jcache.Get_blob() // get next blob if the buffer completed one and containe a second
	}

	return
}
开发者ID:robert-eby,项目名称:tegu,代码行数:66,代码来源:agent.go


示例11: Unregister

/*
	A wrapper allowing a user thread to unregister with a function call rather than
	having to send a message to the dispatcher.
*/
func Unregister(band string, ch chan *Envelope) {
	reg := &Reg_msg{
		band: band,
		ch:   ch,
	}

	msg := ipc.Mk_chmsg()
	msg.Send_req(disp_ch, nil, UNREGISTER, reg, nil) // send the registration to dispatcher for processing
}
开发者ID:prydeep,项目名称:gopkgs,代码行数:13,代码来源:msgrtr.go


示例12: Register

/*
	A wrapper allowing a user thread to register with a function call rather than
	having to send a message to the dispatcher.
*/
func Register(band string, ch chan *Envelope, ldata interface{}) {
	reg := &Reg_msg{
		band:  band,
		ldata: ldata,
		ch:    ch,
	}

	msg := ipc.Mk_chmsg()
	msg.Send_req(disp_ch, nil, REGISTER, reg, nil) // send the registration to dispatcher for processing
}
开发者ID:prydeep,项目名称:gopkgs,代码行数:14,代码来源:msgrtr.go


示例13: deal_with

/*
	Deal with input from the other side sent to the http url.
	This function is invoked directly by the http listener and as such we get no 'user data'
	so we rely on globals in order to be able to function.  (There might be a way to deal
	with this using a closure, but I'm not taking the time to go down that path until
	other more important things are implemented.)

	We assume that the body contains one complete json struct which might contain
	several messages.

	This is invoked as a goroutine by the http environment and when this returns the
	session to the requestor is closed. So, we must ensure that we block until all
	output has been sent to the session before we return.  We do this by creating a
	channel and we wait on a single message on that channel.  The channel is passed in
	the datablock. Once we have the message, then we return.
*/
func deal_with(out http.ResponseWriter, in *http.Request) {
	var (
		state string = "ERROR"
		msg   string
	)

	out.Header().Set("Content-Type", "application/json") // announce that everything out of this is json
	out.WriteHeader(http.StatusOK)                       // if we dealt with it, then it's always OK; requests errors in the output if there were any

	sheep.Baa(2, "dealing with a request")

	data_blk := &Data_block{}
	err := dig_data(in, data_blk)

	if err != nil { // missing or bad data -- punt early
		sheep.Baa(1, "msgrtr/http: missing or badly formatted data: %s: %s", in.Method, err)
		fmt.Fprintf(out, `{ "status": "ERROR", "comment": "missing or badly formatted data: %s", err }`) // error stuff back to user
		return
	}

	switch in.Method {
	case "PUT":
		msg = "PUT requests are unsupported"

	case "POST":
		sheep.Baa(2, "deal_with called for post")

		if len(data_blk.Events) <= 0 {
			sheep.Baa(1, "data block has no events?????")
		} else {
			data_blk.out = out
			data_blk.rel_ch = make(chan int, 1)

			state = "OK"
			sheep.Baa(2, "data: type=%s", data_blk.Events[0].Event_type)
			req := ipc.Mk_chmsg()
			req.Send_req(disp_ch, nil, RAW_BLOCK, data_blk, nil) // pass to dispatcher to process
			<-data_blk.rel_ch                                    // wait on the dispatcher to signal ok to go on; we don't care what comes back
		}

	case "DELETE":
		msg = "DELETE requests are unsupported"

	case "GET":
		msg = "GET requests are unsupported"

	default:
		sheep.Baa(1, "deal_with called for unrecognised method: %s", in.Method)
		msg = fmt.Sprintf("unrecognised method: %s", in.Method)
	}

	if state == "ERROR" {
		fmt.Fprintf(out, fmt.Sprintf(`{ "endstate": { "status": %q, "comment": %q } }`, state, msg)) // send back a failure/error state
	}
}
开发者ID:prydeep,项目名称:gopkgs,代码行数:71,代码来源:msgrtr.go


示例14: lookupMirror

/*
 * Given a name, find the mirror that goes with the name.
 */
func lookupMirror(name string, cookie string) (mirror *gizmos.Pledge_mirror) {
	req := ipc.Mk_chmsg()
	my_ch := make(chan *ipc.Chmsg) // allocate channel for responses to our requests
	defer close(my_ch)
	req.Send_req(rmgr_ch, my_ch, REQ_GET, []*string{&name, &cookie}, nil)
	req = <-my_ch
	if req.State == nil {
		mi := req.Response_data.(*gizmos.Pledge) // assert to iface pointer
		mirror = (*mi).(*gizmos.Pledge_mirror)   // assert to correct type
	}
	return
}
开发者ID:krjoshi,项目名称:tegu,代码行数:15,代码来源:http_mirror_api.go


示例15: pass_push_res

/*
	For a single passthrough pledge, this function sets things up and sends needed requests to the fq-manger to
	create any necessary flow-mods.

	We send the following information to fq_mgr:
		source mac or endpoint	(VM-- the host in the pledge)
		source IP and optionally port and protocol more specific reservations
		expiry
		switch	(physical host -- compute node)

	Errors are returned to res_mgr via channel, but asycnh; we do not wait for responses to each message
	generated here.

	To_limit is a cap to the expiration time sent when creating a flow-mod.  OVS (and others we assume)
	use an unsigned int32 as a hard timeout value, and thus have an upper limit of just over 18 hours. If
	to_limit is > 0, we'll ensure that the timeout passed on the request to fq-mgr won't exceed  the limit,
 	and we assume that this function is called periodically to update long running reservations.
*/
func pass_push_res(gp *gizmos.Pledge, rname *string, ch chan *ipc.Chmsg, to_limit int64) {
	var (
		msg *ipc.Chmsg
	)

	now := time.Now().Unix()

	p, ok := (*gp).(*gizmos.Pledge_pass) // generic pledge better be a passthrough pledge!
	if !ok {
		rm_sheep.Baa(1, "internal error in pass_push_reservation: pledge isn't a passthrough pledge")
		(*gp).Set_pushed() // prevent looping
		return
	}

	host, _, _, expiry, proto := p.Get_values() // reservation info that we need

	ip := name2ip(host)

	if ip != nil { // good ip addresses so we're good to go
		freq := Mk_fqreq(rname)   // default flow mod request with empty match/actions (for bw requests, we don't need priority or such things)
		freq.Match.Smac = ip      // fq_mgr has conversion map to convert to mac
		freq.Swid = p.Get_phost() // the phyiscal host where the VM lives and where fmods need to be deposited

		freq.Cookie = 0xffff // should be ignored, if we see this out there we've got problems

		if (*p).Is_paused() {
			freq.Expiry = time.Now().Unix() + 15 // if reservation shows paused, then we set the expiration to 15s from now  which should force the flow-mods out
		} else {
			if to_limit > 0 && expiry > now+to_limit {
				freq.Expiry = now + to_limit // expiry must be capped so as not to overflow virtual switch variable size
			} else {
				freq.Expiry = expiry
			}
		}
		freq.Id = rname

		freq.Extip = &empty_str

		// this will change when ported to endpoint branch as the endpoint allows address and port 'in line'
		freq.Match.Ip1 = proto // the proto on the reservation should be [{udp|tcp:}]address[:port]
		freq.Match.Ip2 = nil
		freq.Espq = nil
		dup_str := ""
		freq.Exttyp = &dup_str

		rm_sheep.Baa(1, "pushing passthru reservation: %s", p)
		msg = ipc.Mk_chmsg()
		msg.Send_req(fq_ch, ch, REQ_PT_RESERVE, freq, nil) // queue work with fq-manger to read the struct and send cmd(s) to agent to get it done

		p.Set_pushed() // safe to mark the pledge as having been pushed.
	}
}
开发者ID:prydeep,项目名称:tegu,代码行数:70,代码来源:res_mgr_pt.go


示例16: getMirrors

/*
 * Return a string array of mirror names in the reservation cache.
 */
func getMirrors() []string {
	req := ipc.Mk_chmsg()
	my_ch := make(chan *ipc.Chmsg) // allocate channel for responses to our requests
	defer close(my_ch)
	req.Send_req(rmgr_ch, my_ch, REQ_GET_MIRRORS, nil, nil) // push it into the reservation manager which will drive flow-mods etc
	req = <-my_ch
	if req.State == nil {
		rv := string(*req.Response_data.(*string))
		return strings.Split(rv, " ")
	} else {
		return []string{}
	}
}
开发者ID:krjoshi,项目名称:tegu,代码行数:16,代码来源:http_mirror_api.go


示例17: add_ulcap

/*
	Set the user link capacity and forward it on to the network manager. We expect this
	to be a request from the far side (user/admin) or read from the chkpt file so
	the value is passed as a string (which is also what network wants too.
*/
func (inv *Inventory) add_ulcap( name *string, sval *string ) {
	val := clike.Atoi( *sval )

	pdata := make( []*string, 2 )		// parameters for message to network
	pdata[0] = name
	pdata[1] = sval

	if val >= 0 && val < 101 {
		rm_sheep.Baa( 2, "adding user cap: %s %d", *name, val )
		inv.ulcap_cache[*name] = val

		req := ipc.Mk_chmsg( )
		req.Send_req( nw_ch, nil, REQ_SETULCAP, pdata, nil ) 				// push into the network environment

	} else {
		if val == -1 {
			delete( inv.ulcap_cache, *name )
			req := ipc.Mk_chmsg( )
			req.Send_req( nw_ch, nil, REQ_SETULCAP, pdata, nil ) 				// push into the network environment
		} else {
			rm_sheep.Baa( 1, "user link capacity not set %d is out of range (1-100)", val )
		}
	}
}
开发者ID:att,项目名称:tegu,代码行数:29,代码来源:res_mgr.go


示例18: table9x_fmods

/*
	Deprecated -- these should no longer be set by tegu and if really needed should
		be set by the ql_bw*fmods and other agent scripts.


	Push table 9x flow-mods. The flowmods we toss into the 90 range of
	tables generally serve to mark metadata in a packet since metadata
	cannot be marked prior to a resub action (flaw in OVS if you ask me).

	Marking metadata is needed so that when one of our f-mods match we can
	resubmit into table 0 without triggering a loop, or a match of any
	of our other rules.

	Table is the table number (we assume 9x, but it could be anything)
	Meta is a string supplying the value/mask that is used on the action (e.g. 0x02/0x02)
	to set the 00000010 bit as an and operation.
	Cookie is the cookie value used on the f-mod.
*/
func table9x_fmods( rname *string, host string, table int, meta string, cookie int ) {
		fq_data := Mk_fqreq( rname )							// f-mod request with defaults (output==none)
		fq_data.Table = table
		fq_data.Cookie = cookie
		fq_data.Expiry = 0										// never expire

		// CAUTION: fq_mgr generic fmod needs to be changed and when it does these next three lines will need to change too
		fq_data.Espq = gizmos.Mk_spq( host, -1, -1 )			// send to specific host
		dup_str := "br-int"										// these go to br-int only
		fq_data.Swid = &dup_str

		fq_data.Action.Meta = &meta								// sole purpose is to set metadata

		msg := ipc.Mk_chmsg()
		msg.Send_req( fq_ch, nil, REQ_GEN_FMOD, fq_data, nil )			// no response right now -- eventually we want an asynch error
}
开发者ID:att,项目名称:tegu,代码行数:34,代码来源:res_mgr.go


示例19: send_meta_fm

/*
	Not to be confused with send_meta_fmods in res_mgr. This needs to be extended
	such that resmgr can just send fq-mgr a request to invoke this.

*/
func send_meta_fm(hlist []string, table int, cookie int, pattern string) {
	tmsg := ipc.Mk_chmsg()

	msg := &agent_cmd{Ctype: "action_list"} // create an agent message
	msg.Actions = make([]action, 1)
	msg.Actions[0].Atype = "flowmod"
	msg.Actions[0].Hosts = hlist
	msg.Actions[0].Fdata = make([]string, 1)
	msg.Actions[0].Fdata[0] = fmt.Sprintf(`-T %d -I -t 0 --match --action -m %s -N add 0x%x br-int`, table, pattern, cookie)

	json, err := json.Marshal(msg) // bundle into a json string
	if err != nil {
		fq_sheep.Baa(0, "steer: unable to build json to set meta flow mod")
	} else {
		fq_sheep.Baa(2, "meta json: %s", json)
		tmsg.Send_req(am_ch, nil, REQ_SENDSHORT, string(json), nil) // send as a short request to one agent
	}
}
开发者ID:robert-eby,项目名称:tegu,代码行数:23,代码来源:fq_mgr_steer.go


示例20: name2ip

/*
	Given a name, send a request to the network manager to translate it to an IP address.
	If the name is nil or empty, we return nil. This is legit for steering in the case of
	L* endpoint specification.
*/
func name2ip(name *string) (ip *string) {
	ip = nil

	if name == nil || *name == "" {
		return
	}

	ch := make(chan *ipc.Chmsg)
	defer close(ch) // close it on return
	msg := ipc.Mk_chmsg()
	msg.Send_req(nw_ch, ch, REQ_GETIP, name, nil)
	msg = <-ch
	if msg.State == nil { // success
		ip = msg.Response_data.(*string)
	}

	return
}
开发者ID:robert-eby,项目名称:tegu,代码行数:23,代码来源:res_mgr.go



注:本文中的github.com/att/gopkgs/ipc.Mk_chmsg函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ipc.Chmsg类代码示例发布时间:2022-05-24
下一篇:
Golang connman.Cmgr类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap