- setupDhcpFlowEntry(dpnId, NwConstants.DHCP_TABLE, vmMacAddress, NwConstants.ADD_FLOW);
- }
-
- private void setupDhcpFlowEntry(BigInteger dpId, short tableId, String vmMacAddress, int addOrRemove) {
- if (dpId == null || dpId == DHCPMConstants.INVALID_DPID || vmMacAddress == null) {
- return;
- }
- List<MatchInfo> matches = new ArrayList<MatchInfo>();
-
- matches.add(new MatchInfo(MatchFieldType.eth_type,
- new long[] { NwConstants.ETHTYPE_IPV4 }));
- matches.add(new MatchInfo(MatchFieldType.ip_proto,
- new long[] { IPProtocols.UDP.intValue() }));
- matches.add(new MatchInfo(MatchFieldType.udp_src,
- new long[] { DHCPMConstants.dhcpClientPort }));
- matches.add(new MatchInfo(MatchFieldType.udp_dst,
- new long[] { DHCPMConstants.dhcpServerPort }));
- matches.add(new MatchInfo(MatchFieldType.eth_src,
- new String[] { vmMacAddress }));
-
- List<InstructionInfo> instructions = new ArrayList<InstructionInfo>();
- List<ActionInfo> actionsInfos = new ArrayList<ActionInfo>();
-
- // Punt to controller
- actionsInfos.add(new ActionInfo(ActionType.punt_to_controller,
- new String[] {}));
- instructions.add(new InstructionInfo(InstructionType.write_actions,
- actionsInfos));
- if (addOrRemove == NwConstants.DEL_FLOW) {
- FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId,
- getDhcpFlowRef(dpId, tableId, vmMacAddress),
- DHCPMConstants.DEFAULT_DHCP_FLOW_PRIORITY, "DHCP", 0, 0,
- DHCPMConstants.COOKIE_DHCP_BASE, matches, null);
- logger.trace("Removing DHCP Flow DpId {}, vmMacAddress {}", dpId, vmMacAddress);
- mdsalUtil.removeFlow(flowEntity);
- } else {
- FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, tableId,
- getDhcpFlowRef(dpId, tableId, vmMacAddress),DHCPMConstants.DEFAULT_DHCP_FLOW_PRIORITY, "DHCP", 0, 0,
- DHCPMConstants.COOKIE_DHCP_BASE, matches, instructions);
- logger.trace("Installing DHCP Flow DpId {}, vmMacAddress {}", dpId, vmMacAddress);
- mdsalUtil.installFlow(flowEntity);
- }
- }
-
- private String getDhcpFlowRef(BigInteger dpId, long tableId, String vmMacAddress) {
- return new StringBuffer().append(DHCPMConstants.FLOWID_PREFIX)
- .append(dpId).append(NwConstants.FLOWID_SEPARATOR)
- .append(tableId).append(NwConstants.FLOWID_SEPARATOR)
- .append(vmMacAddress).toString();