2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
11 import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.applyActionIns;
12 import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.instructions;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.List;
18 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
19 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.FlowMap;
20 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Action;
21 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.AllowAction;
22 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.SubjectFeatures;
23 import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * Manage the table that assigns source endpoint group, bridge domain, and
35 * router domain to registers to be used by other tables.
37 public class ExternalMapper extends FlowTable {
39 protected static final Logger LOG = LoggerFactory.getLogger(ExternalMapper.class);
41 public static short TABLE_ID;
43 public ExternalMapper(OfContext ctx, short tableId) {
45 this.TABLE_ID=tableId;
49 public short getTableId() {
54 public void sync(NodeId nodeId, PolicyInfo policyInfo, FlowMap flowMap) throws Exception {
56 if (ctx.getSwitchManager().getExternalPorts(nodeId) == null) {
57 LOG.trace("No external ports found for node: {}", nodeId);
61 flowMap.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null));
63 // Drop IP traffic that doesn't match a source IP rule
64 flowMap.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(2), FlowUtils.ARP));
65 flowMap.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(2), FlowUtils.IPv4));
66 flowMap.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(2), FlowUtils.IPv6));
67 l3flow(flowMap,nodeId, 100, true);
68 l3flow(flowMap,nodeId, 200, false);
71 private void l3flow(FlowMap flowMap, NodeId nodeId, Integer priority, boolean arp) {
73 List<ActionBuilder> actionBuilderList = new ArrayList<ActionBuilder>();
75 Action action = SubjectFeatures.getAction(AllowAction.DEFINITION.getId());
76 actionBuilderList = action.updateAction(actionBuilderList, new HashMap<String, Object>(), 0, null);
79 Long etherType = null;
82 etherType = FlowUtils.ARP;
84 etherType = FlowUtils.IPv4;
87 FlowId flowid = new FlowId(new StringBuilder().append("ExternalMapper")
91 Flow flow = base().setPriority(priority)
94 new MatchBuilder().setEthernetMatch(FlowUtils.ethernetMatch(null, null, etherType))
97 .setInstructions(instructions(applyActionIns(actionBuilderList)))
100 flowMap.writeFlow(nodeId, TABLE_ID, flow);