Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
32 changed files
with
1415 additions
and
307 deletions
1 | +package org.onlab.onos.cluster; | ||
2 | + | ||
3 | +import org.onlab.onos.event.AbstractEvent; | ||
4 | + | ||
5 | +/** | ||
6 | + * Describes cluster-related event. | ||
7 | + */ | ||
8 | +public class ClusterEvent extends AbstractEvent<ClusterEvent.Type, ControllerInstance> { | ||
9 | + | ||
10 | + /** | ||
11 | + * Type of device events. | ||
12 | + */ | ||
13 | + public enum Type { | ||
14 | + /** | ||
15 | + * Signifies that a new cluster instance has been administratively added. | ||
16 | + */ | ||
17 | + INSTANCE_ADDED, | ||
18 | + | ||
19 | + /** | ||
20 | + * Signifies that a cluster instance has been administratively removed. | ||
21 | + */ | ||
22 | + INSTANCE_REMOVED, | ||
23 | + | ||
24 | + /** | ||
25 | + * Signifies that a cluster instance became active. | ||
26 | + */ | ||
27 | + INSTANCE_ACTIVE, | ||
28 | + | ||
29 | + /** | ||
30 | + * Signifies that a cluster instance became inactive. | ||
31 | + */ | ||
32 | + INSTANCE_INACTIVE | ||
33 | + } | ||
34 | + // TODO: do we need to fix the verv/adjective mix? discuss | ||
35 | + | ||
36 | + /** | ||
37 | + * Creates an event of a given type and for the specified instance and the | ||
38 | + * current time. | ||
39 | + * | ||
40 | + * @param type cluster event type | ||
41 | + * @param instance cluster device subject | ||
42 | + */ | ||
43 | + public ClusterEvent(Type type, ControllerInstance instance) { | ||
44 | + super(type, instance); | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * Creates an event of a given type and for the specified device and time. | ||
49 | + * | ||
50 | + * @param type device event type | ||
51 | + * @param instance event device subject | ||
52 | + * @param time occurrence time | ||
53 | + */ | ||
54 | + public ClusterEvent(Type type, ControllerInstance instance, long time) { | ||
55 | + super(type, instance, time); | ||
56 | + } | ||
57 | + | ||
58 | +} |
1 | +package org.onlab.onos.cluster; | ||
2 | + | ||
3 | +import java.util.Set; | ||
4 | + | ||
5 | +/** | ||
6 | + * Service for obtaining information about the individual instances within | ||
7 | + * the controller cluster. | ||
8 | + */ | ||
9 | +public interface ClusterService { | ||
10 | + | ||
11 | + /** | ||
12 | + * Returns the set of current cluster members. | ||
13 | + * | ||
14 | + * @return set of cluster members | ||
15 | + */ | ||
16 | + Set<ControllerInstance> getInstances(); | ||
17 | + | ||
18 | + /** | ||
19 | + * Returns the availability state of the specified controller instance. | ||
20 | + * | ||
21 | + * @return availability state | ||
22 | + */ | ||
23 | + ControllerInstance.State getState(ControllerInstance instance); | ||
24 | + // TODO: determine if this would be better attached to ControllerInstance directly | ||
25 | + | ||
26 | + | ||
27 | + // addListener, removeListener | ||
28 | + | ||
29 | +} |
1 | +package org.onlab.onos.cluster; | ||
2 | + | ||
3 | +import org.onlab.packet.IpAddress; | ||
4 | + | ||
5 | +/** | ||
6 | + * Represents a controller instance as a member in a cluster. | ||
7 | + */ | ||
8 | +public interface ControllerInstance { | ||
9 | + | ||
10 | + /** Represents the operational state of the instance. */ | ||
11 | + public enum State { | ||
12 | + /** | ||
13 | + * Signifies that the instance is active and operating normally. | ||
14 | + */ | ||
15 | + ACTIVE, | ||
16 | + | ||
17 | + /** | ||
18 | + * Signifies that the instance is inactive, which means either down or | ||
19 | + * up, but not operational. | ||
20 | + */ | ||
21 | + INACTIVE | ||
22 | + } | ||
23 | + | ||
24 | + /** | ||
25 | + * Returns the instance identifier. | ||
26 | + * | ||
27 | + * @return instance identifier | ||
28 | + */ | ||
29 | + InstanceId id(); | ||
30 | + | ||
31 | + /** | ||
32 | + * Returns the IP address of the controller instance. | ||
33 | + * | ||
34 | + * @return IP address | ||
35 | + */ | ||
36 | + IpAddress ip(); | ||
37 | + | ||
38 | +} |
... | @@ -19,7 +19,7 @@ public class FlowRuleEvent extends AbstractEvent<FlowRuleEvent.Type, FlowRule> { | ... | @@ -19,7 +19,7 @@ public class FlowRuleEvent extends AbstractEvent<FlowRuleEvent.Type, FlowRule> { |
19 | /** | 19 | /** |
20 | * Signifies that a flow rule has been removed. | 20 | * Signifies that a flow rule has been removed. |
21 | */ | 21 | */ |
22 | - RULE_REMOVED, | 22 | + RULE_REMOVED |
23 | } | 23 | } |
24 | 24 | ||
25 | /** | 25 | /** | ... | ... |
... | @@ -23,6 +23,8 @@ public interface FlowRuleService { | ... | @@ -23,6 +23,8 @@ public interface FlowRuleService { |
23 | */ | 23 | */ |
24 | Iterable<FlowEntry> getFlowEntries(DeviceId deviceId); | 24 | Iterable<FlowEntry> getFlowEntries(DeviceId deviceId); |
25 | 25 | ||
26 | + // TODO: add createFlowRule factory method and execute operations method | ||
27 | + | ||
26 | /** | 28 | /** |
27 | * Applies the specified flow rules onto their respective devices. These | 29 | * Applies the specified flow rules onto their respective devices. These |
28 | * flow rules will be retained by the system and re-applied anytime the | 30 | * flow rules will be retained by the system and re-applied anytime the |
... | @@ -46,9 +48,6 @@ public interface FlowRuleService { | ... | @@ -46,9 +48,6 @@ public interface FlowRuleService { |
46 | void removeFlowRules(FlowRule... flowRules); | 48 | void removeFlowRules(FlowRule... flowRules); |
47 | 49 | ||
48 | 50 | ||
49 | - // void addInitialFlowContributor(InitialFlowContributor contributor); | ||
50 | - // void removeInitialFlowContributor(InitialFlowContributor contributor); | ||
51 | - | ||
52 | /** | 51 | /** |
53 | * Adds the specified flow rule listener. | 52 | * Adds the specified flow rule listener. |
54 | * | 53 | * | ... | ... |
... | @@ -7,6 +7,7 @@ | ... | @@ -7,6 +7,7 @@ |
7 | description="ONOS 3rd party dependencies"> | 7 | description="ONOS 3rd party dependencies"> |
8 | <bundle>mvn:commons-lang/commons-lang/2.6</bundle> | 8 | <bundle>mvn:commons-lang/commons-lang/2.6</bundle> |
9 | <bundle>mvn:com.google.guava/guava/18.0</bundle> | 9 | <bundle>mvn:com.google.guava/guava/18.0</bundle> |
10 | + <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> | ||
10 | </feature> | 11 | </feature> |
11 | 12 | ||
12 | <feature name="onos-thirdparty-web" version="1.0.0" | 13 | <feature name="onos-thirdparty-web" version="1.0.0" |
... | @@ -18,6 +19,7 @@ | ... | @@ -18,6 +19,7 @@ |
18 | <bundle>mvn:com.sun.jersey/jersey-core/1.18.1</bundle> | 19 | <bundle>mvn:com.sun.jersey/jersey-core/1.18.1</bundle> |
19 | <bundle>mvn:com.sun.jersey/jersey-server/1.18.1</bundle> | 20 | <bundle>mvn:com.sun.jersey/jersey-server/1.18.1</bundle> |
20 | <bundle>mvn:com.sun.jersey/jersey-servlet/1.18.1</bundle> | 21 | <bundle>mvn:com.sun.jersey/jersey-servlet/1.18.1</bundle> |
22 | + | ||
21 | </feature> | 23 | </feature> |
22 | 24 | ||
23 | <feature name="onos-api" version="1.0.0" | 25 | <feature name="onos-api" version="1.0.0" |
... | @@ -61,7 +63,6 @@ | ... | @@ -61,7 +63,6 @@ |
61 | description="ONOS OpenFlow API, Controller & Providers"> | 63 | description="ONOS OpenFlow API, Controller & Providers"> |
62 | <feature>onos-api</feature> | 64 | <feature>onos-api</feature> |
63 | <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> | 65 | <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> |
64 | - | ||
65 | <bundle>mvn:org.onlab.onos/onos-of-api/1.0.0-SNAPSHOT</bundle> | 66 | <bundle>mvn:org.onlab.onos/onos-of-api/1.0.0-SNAPSHOT</bundle> |
66 | <bundle>mvn:org.onlab.onos/onos-of-ctl/1.0.0-SNAPSHOT</bundle> | 67 | <bundle>mvn:org.onlab.onos/onos-of-ctl/1.0.0-SNAPSHOT</bundle> |
67 | 68 | ||
... | @@ -75,8 +76,9 @@ | ... | @@ -75,8 +76,9 @@ |
75 | 76 | ||
76 | <feature name="onos-app-tvue" version="1.0.0" | 77 | <feature name="onos-app-tvue" version="1.0.0" |
77 | description="ONOS sample topology viewer application"> | 78 | description="ONOS sample topology viewer application"> |
78 | - <feature>onos-api</feature> | ||
79 | <feature>onos-thirdparty-web</feature> | 79 | <feature>onos-thirdparty-web</feature> |
80 | + <feature>onos-api</feature> | ||
81 | + <feature>onos-core</feature> | ||
80 | <bundle>mvn:org.onlab.onos/onos-app-tvue/1.0.0-SNAPSHOT</bundle> | 82 | <bundle>mvn:org.onlab.onos/onos-app-tvue/1.0.0-SNAPSHOT</bundle> |
81 | </feature> | 83 | </feature> |
82 | 84 | ... | ... |
... | @@ -78,6 +78,20 @@ public interface OpenFlowController { | ... | @@ -78,6 +78,20 @@ public interface OpenFlowController { |
78 | public void removePacketListener(PacketListener listener); | 78 | public void removePacketListener(PacketListener listener); |
79 | 79 | ||
80 | /** | 80 | /** |
81 | + * Register a listener for OF msg events. | ||
82 | + * | ||
83 | + * @param listener the listener to notify | ||
84 | + */ | ||
85 | + public void addEventListener(OpenFlowEventListener listener); | ||
86 | + | ||
87 | + /** | ||
88 | + * Unregister a listener. | ||
89 | + * | ||
90 | + * @param listener the listener to unregister | ||
91 | + */ | ||
92 | + public void removeEventListener(OpenFlowEventListener listener); | ||
93 | + | ||
94 | + /** | ||
81 | * Send a message to a particular switch. | 95 | * Send a message to a particular switch. |
82 | * @param dpid the switch to send to. | 96 | * @param dpid the switch to send to. |
83 | * @param msg the message to send | 97 | * @param msg the message to send | ... | ... |
1 | +package org.onlab.onos.openflow.controller; | ||
2 | + | ||
3 | +import org.projectfloodlight.openflow.protocol.OFMessage; | ||
4 | + | ||
5 | + | ||
6 | +/** | ||
7 | + * Notifies providers about openflow msg events. | ||
8 | + */ | ||
9 | +public interface OpenFlowEventListener { | ||
10 | + | ||
11 | + /** | ||
12 | + * Handles the message event. | ||
13 | + * | ||
14 | + * @param msg the message | ||
15 | + */ | ||
16 | + public void handleMessage(Dpid dpid, OFMessage msg); | ||
17 | +} |
... | @@ -63,4 +63,16 @@ public class OpenflowControllerAdapter implements OpenFlowController { | ... | @@ -63,4 +63,16 @@ public class OpenflowControllerAdapter implements OpenFlowController { |
63 | @Override | 63 | @Override |
64 | public void setRole(Dpid dpid, RoleState role) { | 64 | public void setRole(Dpid dpid, RoleState role) { |
65 | } | 65 | } |
66 | + | ||
67 | + @Override | ||
68 | + public void addEventListener(OpenFlowEventListener listener) { | ||
69 | + // TODO Auto-generated method stub | ||
70 | + | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public void removeEventListener(OpenFlowEventListener listener) { | ||
75 | + // TODO Auto-generated method stub | ||
76 | + | ||
77 | + } | ||
66 | } | 78 | } | ... | ... |
... | @@ -15,107 +15,27 @@ | ... | @@ -15,107 +15,27 @@ |
15 | 15 | ||
16 | <description>ONOS OpenFlow controller subsystem API</description> | 16 | <description>ONOS OpenFlow controller subsystem API</description> |
17 | 17 | ||
18 | - <properties> | ||
19 | - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
20 | - <powermock.version>1.5.5</powermock.version> | ||
21 | - <restlet.version>2.1.4</restlet.version> | ||
22 | - <cobertura-maven-plugin.version>2.6</cobertura-maven-plugin.version> | ||
23 | - <!-- Following 2 findbugs version needs to be updated in sync to match the | ||
24 | - findbugs version used in findbugs-plugin --> | ||
25 | - <findbugs.version>3.0.0</findbugs.version> | ||
26 | - <findbugs-plugin.version>3.0.0</findbugs-plugin.version> | ||
27 | - <findbugs.effort>Max</findbugs.effort> | ||
28 | - <findbugs.excludeFilterFile>${project.basedir}/conf/findbugs/exclude.xml | ||
29 | - </findbugs.excludeFilterFile> | ||
30 | - <checkstyle-plugin.version>2.12</checkstyle-plugin.version> | ||
31 | - <!-- To publish javadoc to github, | ||
32 | - uncomment com.github.github site-maven-plugin and | ||
33 | - see https://github.com/OPENNETWORKINGLAB/ONOS/pull/425 | ||
34 | - <github.global.server>github</github.global.server> | ||
35 | - --> | ||
36 | - <metrics.version>3.0.2</metrics.version> | ||
37 | - <maven.surefire.plugin.version>2.16</maven.surefire.plugin.version> | ||
38 | - </properties> | ||
39 | - | ||
40 | <dependencies> | 18 | <dependencies> |
41 | <dependency> | 19 | <dependency> |
42 | <groupId>org.onlab.onos</groupId> | 20 | <groupId>org.onlab.onos</groupId> |
43 | <artifactId>onos-of-api</artifactId> | 21 | <artifactId>onos-of-api</artifactId> |
44 | </dependency> | 22 | </dependency> |
45 | - <!-- ONOS's direct dependencies --> | ||
46 | - <dependency> | ||
47 | - <groupId>org.apache.felix</groupId> | ||
48 | - <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
49 | - <version>1.9.6</version> | ||
50 | - </dependency> | ||
51 | - <dependency> | ||
52 | - <groupId>ch.qos.logback</groupId> | ||
53 | - <artifactId>logback-classic</artifactId> | ||
54 | - <version>1.1.2</version> | ||
55 | - </dependency> | ||
56 | - <dependency> | ||
57 | - <groupId>ch.qos.logback</groupId> | ||
58 | - <artifactId>logback-core</artifactId> | ||
59 | - <version>1.1.2</version> | ||
60 | - </dependency> | ||
61 | - <dependency> | ||
62 | - <groupId>org.slf4j</groupId> | ||
63 | - <artifactId>slf4j-api</artifactId> | ||
64 | - <version>1.7.5</version> | ||
65 | - </dependency> | ||
66 | - <dependency> | ||
67 | - <!-- findbugs suppression annotation and @GuardedBy, etc. --> | ||
68 | - <groupId>com.google.code.findbugs</groupId> | ||
69 | - <artifactId>annotations</artifactId> | ||
70 | - <version>${findbugs.version}</version> | ||
71 | - </dependency> | ||
72 | <dependency> | 23 | <dependency> |
73 | - <groupId>org.projectfloodlight</groupId> | ||
74 | - <artifactId>openflowj</artifactId> | ||
75 | - <version>0.3.8-SNAPSHOT</version> | ||
76 | - </dependency> | ||
77 | - <!-- Floodlight's dependencies --> | ||
78 | - <dependency> | ||
79 | - <!-- dependency to old version of netty? --> | ||
80 | <groupId>io.netty</groupId> | 24 | <groupId>io.netty</groupId> |
81 | <artifactId>netty</artifactId> | 25 | <artifactId>netty</artifactId> |
82 | - <version>3.9.2.Final</version> | ||
83 | - </dependency> | ||
84 | - <!-- Dependency for libraries used for testing --> | ||
85 | - <dependency> | ||
86 | - <groupId>junit</groupId> | ||
87 | - <artifactId>junit</artifactId> | ||
88 | - <version>4.11</version> | ||
89 | - <scope>test</scope> | ||
90 | - </dependency> | ||
91 | - <dependency> | ||
92 | - <groupId>org.easymock</groupId> | ||
93 | - <artifactId>easymock</artifactId> | ||
94 | - <version>3.2</version> | ||
95 | - <scope>test</scope> | ||
96 | </dependency> | 26 | </dependency> |
97 | <dependency> | 27 | <dependency> |
98 | - <groupId>org.powermock</groupId> | 28 | + <groupId>org.apache.felix</groupId> |
99 | - <artifactId>powermock-module-junit4</artifactId> | 29 | + <artifactId>org.apache.felix.scr.annotations</artifactId> |
100 | - <version>${powermock.version}</version> | ||
101 | - <scope>test</scope> | ||
102 | - </dependency> | ||
103 | - <dependency> | ||
104 | - <groupId>org.powermock</groupId> | ||
105 | - <artifactId>powermock-api-easymock</artifactId> | ||
106 | - <version>${powermock.version}</version> | ||
107 | - <scope>test</scope> | ||
108 | </dependency> | 30 | </dependency> |
109 | </dependencies> | 31 | </dependencies> |
110 | 32 | ||
111 | - | ||
112 | <build> | 33 | <build> |
113 | <plugins> | 34 | <plugins> |
114 | <plugin> | 35 | <plugin> |
115 | <groupId>org.apache.felix</groupId> | 36 | <groupId>org.apache.felix</groupId> |
116 | <artifactId>maven-scr-plugin</artifactId> | 37 | <artifactId>maven-scr-plugin</artifactId> |
117 | </plugin> | 38 | </plugin> |
118 | - | ||
119 | </plugins> | 39 | </plugins> |
120 | </build> | 40 | </build> |
121 | 41 | ... | ... |
1 | package org.onlab.onos.openflow.controller.impl; | 1 | package org.onlab.onos.openflow.controller.impl; |
2 | 2 | ||
3 | +import static org.onlab.util.Tools.namedThreads; | ||
4 | + | ||
3 | import java.util.HashSet; | 5 | import java.util.HashSet; |
4 | import java.util.Set; | 6 | import java.util.Set; |
5 | import java.util.concurrent.ConcurrentHashMap; | 7 | import java.util.concurrent.ConcurrentHashMap; |
8 | +import java.util.concurrent.ExecutorService; | ||
9 | +import java.util.concurrent.Executors; | ||
6 | import java.util.concurrent.locks.Lock; | 10 | import java.util.concurrent.locks.Lock; |
7 | import java.util.concurrent.locks.ReentrantLock; | 11 | import java.util.concurrent.locks.ReentrantLock; |
8 | 12 | ||
... | @@ -13,6 +17,7 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -13,6 +17,7 @@ import org.apache.felix.scr.annotations.Service; |
13 | import org.onlab.onos.openflow.controller.DefaultOpenFlowPacketContext; | 17 | import org.onlab.onos.openflow.controller.DefaultOpenFlowPacketContext; |
14 | import org.onlab.onos.openflow.controller.Dpid; | 18 | import org.onlab.onos.openflow.controller.Dpid; |
15 | import org.onlab.onos.openflow.controller.OpenFlowController; | 19 | import org.onlab.onos.openflow.controller.OpenFlowController; |
20 | +import org.onlab.onos.openflow.controller.OpenFlowEventListener; | ||
16 | import org.onlab.onos.openflow.controller.OpenFlowPacketContext; | 21 | import org.onlab.onos.openflow.controller.OpenFlowPacketContext; |
17 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; | 22 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; |
18 | import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; | 23 | import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; |
... | @@ -27,6 +32,7 @@ import org.slf4j.LoggerFactory; | ... | @@ -27,6 +32,7 @@ import org.slf4j.LoggerFactory; |
27 | 32 | ||
28 | import com.google.common.collect.ArrayListMultimap; | 33 | import com.google.common.collect.ArrayListMultimap; |
29 | import com.google.common.collect.Multimap; | 34 | import com.google.common.collect.Multimap; |
35 | +import com.google.common.collect.Sets; | ||
30 | 36 | ||
31 | @Component(immediate = true) | 37 | @Component(immediate = true) |
32 | @Service | 38 | @Service |
... | @@ -35,6 +41,10 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -35,6 +41,10 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
35 | private static final Logger log = | 41 | private static final Logger log = |
36 | LoggerFactory.getLogger(OpenFlowControllerImpl.class); | 42 | LoggerFactory.getLogger(OpenFlowControllerImpl.class); |
37 | 43 | ||
44 | + private final ExecutorService executor = Executors.newFixedThreadPool(16, | ||
45 | + namedThreads("of-event-%d")); | ||
46 | + | ||
47 | + | ||
38 | protected ConcurrentHashMap<Dpid, OpenFlowSwitch> connectedSwitches = | 48 | protected ConcurrentHashMap<Dpid, OpenFlowSwitch> connectedSwitches = |
39 | new ConcurrentHashMap<Dpid, OpenFlowSwitch>(); | 49 | new ConcurrentHashMap<Dpid, OpenFlowSwitch>(); |
40 | protected ConcurrentHashMap<Dpid, OpenFlowSwitch> activeMasterSwitches = | 50 | protected ConcurrentHashMap<Dpid, OpenFlowSwitch> activeMasterSwitches = |
... | @@ -43,11 +53,12 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -43,11 +53,12 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
43 | new ConcurrentHashMap<Dpid, OpenFlowSwitch>(); | 53 | new ConcurrentHashMap<Dpid, OpenFlowSwitch>(); |
44 | 54 | ||
45 | protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent(); | 55 | protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent(); |
46 | - protected Set<OpenFlowSwitchListener> ofEventListener = new HashSet<>(); | 56 | + protected Set<OpenFlowSwitchListener> ofSwitchListener = new HashSet<>(); |
47 | 57 | ||
48 | protected Multimap<Integer, PacketListener> ofPacketListener = | 58 | protected Multimap<Integer, PacketListener> ofPacketListener = |
49 | ArrayListMultimap.create(); | 59 | ArrayListMultimap.create(); |
50 | 60 | ||
61 | + protected Set<OpenFlowEventListener> ofEventListener = Sets.newHashSet(); | ||
51 | 62 | ||
52 | private final Controller ctrl = new Controller(); | 63 | private final Controller ctrl = new Controller(); |
53 | 64 | ||
... | @@ -93,14 +104,14 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -93,14 +104,14 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
93 | 104 | ||
94 | @Override | 105 | @Override |
95 | public void addListener(OpenFlowSwitchListener listener) { | 106 | public void addListener(OpenFlowSwitchListener listener) { |
96 | - if (!ofEventListener.contains(listener)) { | 107 | + if (!ofSwitchListener.contains(listener)) { |
97 | - this.ofEventListener.add(listener); | 108 | + this.ofSwitchListener.add(listener); |
98 | } | 109 | } |
99 | } | 110 | } |
100 | 111 | ||
101 | @Override | 112 | @Override |
102 | public void removeListener(OpenFlowSwitchListener listener) { | 113 | public void removeListener(OpenFlowSwitchListener listener) { |
103 | - this.ofEventListener.remove(listener); | 114 | + this.ofSwitchListener.remove(listener); |
104 | } | 115 | } |
105 | 116 | ||
106 | @Override | 117 | @Override |
... | @@ -114,6 +125,16 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -114,6 +125,16 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
114 | } | 125 | } |
115 | 126 | ||
116 | @Override | 127 | @Override |
128 | + public void addEventListener(OpenFlowEventListener listener) { | ||
129 | + ofEventListener.add(listener); | ||
130 | + } | ||
131 | + | ||
132 | + @Override | ||
133 | + public void removeEventListener(OpenFlowEventListener listener) { | ||
134 | + ofEventListener.remove(listener); | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
117 | public void write(Dpid dpid, OFMessage msg) { | 138 | public void write(Dpid dpid, OFMessage msg) { |
118 | this.getSwitch(dpid).sendMsg(msg); | 139 | this.getSwitch(dpid).sendMsg(msg); |
119 | } | 140 | } |
... | @@ -122,7 +143,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -122,7 +143,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
122 | public void processPacket(Dpid dpid, OFMessage msg) { | 143 | public void processPacket(Dpid dpid, OFMessage msg) { |
123 | switch (msg.getType()) { | 144 | switch (msg.getType()) { |
124 | case PORT_STATUS: | 145 | case PORT_STATUS: |
125 | - for (OpenFlowSwitchListener l : ofEventListener) { | 146 | + for (OpenFlowSwitchListener l : ofSwitchListener) { |
126 | l.portChanged(dpid, (OFPortStatus) msg); | 147 | l.portChanged(dpid, (OFPortStatus) msg); |
127 | } | 148 | } |
128 | break; | 149 | break; |
... | @@ -134,6 +155,12 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -134,6 +155,12 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
134 | p.handlePacket(pktCtx); | 155 | p.handlePacket(pktCtx); |
135 | } | 156 | } |
136 | break; | 157 | break; |
158 | + case FLOW_REMOVED: | ||
159 | + case ERROR: | ||
160 | + case STATS_REPLY: | ||
161 | + case BARRIER_REPLY: | ||
162 | + executor.submit(new OFMessageHandler(dpid, msg)); | ||
163 | + break; | ||
137 | default: | 164 | default: |
138 | log.warn("Handling message type {} not yet implemented {}", | 165 | log.warn("Handling message type {} not yet implemented {}", |
139 | msg.getType(), msg); | 166 | msg.getType(), msg); |
... | @@ -164,7 +191,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -164,7 +191,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
164 | } else { | 191 | } else { |
165 | log.error("Added switch {}", dpid); | 192 | log.error("Added switch {}", dpid); |
166 | connectedSwitches.put(dpid, sw); | 193 | connectedSwitches.put(dpid, sw); |
167 | - for (OpenFlowSwitchListener l : ofEventListener) { | 194 | + for (OpenFlowSwitchListener l : ofSwitchListener) { |
168 | l.switchAdded(dpid); | 195 | l.switchAdded(dpid); |
169 | } | 196 | } |
170 | return true; | 197 | return true; |
... | @@ -277,7 +304,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -277,7 +304,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
277 | if (sw == null) { | 304 | if (sw == null) { |
278 | sw = activeEqualSwitches.remove(dpid); | 305 | sw = activeEqualSwitches.remove(dpid); |
279 | } | 306 | } |
280 | - for (OpenFlowSwitchListener l : ofEventListener) { | 307 | + for (OpenFlowSwitchListener l : ofSwitchListener) { |
281 | l.switchRemoved(dpid); | 308 | l.switchRemoved(dpid); |
282 | } | 309 | } |
283 | } | 310 | } |
... | @@ -288,5 +315,23 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -288,5 +315,23 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
288 | } | 315 | } |
289 | } | 316 | } |
290 | 317 | ||
318 | + private final class OFMessageHandler implements Runnable { | ||
319 | + | ||
320 | + private final OFMessage msg; | ||
321 | + private final Dpid dpid; | ||
322 | + | ||
323 | + public OFMessageHandler(Dpid dpid, OFMessage msg) { | ||
324 | + this.msg = msg; | ||
325 | + this.dpid = dpid; | ||
326 | + } | ||
327 | + | ||
328 | + @Override | ||
329 | + public void run() { | ||
330 | + for (OpenFlowEventListener listener : ofEventListener) { | ||
331 | + listener.handleMessage(dpid, msg); | ||
332 | + } | ||
333 | + } | ||
334 | + | ||
335 | + } | ||
291 | 336 | ||
292 | } | 337 | } | ... | ... |
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowModBuilder.java
0 → 100644
1 | +package org.onlab.onos.provider.of.flow.impl; | ||
2 | + | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
5 | +import java.util.Collections; | ||
6 | +import java.util.LinkedList; | ||
7 | +import java.util.List; | ||
8 | + | ||
9 | +import org.onlab.onos.net.flow.FlowRule; | ||
10 | +import org.onlab.onos.net.flow.TrafficSelector; | ||
11 | +import org.onlab.onos.net.flow.TrafficTreatment; | ||
12 | +import org.onlab.onos.net.flow.criteria.Criteria.EthCriterion; | ||
13 | +import org.onlab.onos.net.flow.criteria.Criteria.EthTypeCriterion; | ||
14 | +import org.onlab.onos.net.flow.criteria.Criteria.IPCriterion; | ||
15 | +import org.onlab.onos.net.flow.criteria.Criteria.IPProtocolCriterion; | ||
16 | +import org.onlab.onos.net.flow.criteria.Criteria.PortCriterion; | ||
17 | +import org.onlab.onos.net.flow.criteria.Criteria.VlanIdCriterion; | ||
18 | +import org.onlab.onos.net.flow.criteria.Criteria.VlanPcpCriterion; | ||
19 | +import org.onlab.onos.net.flow.criteria.Criterion; | ||
20 | +import org.onlab.onos.net.flow.instructions.Instruction; | ||
21 | +import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction; | ||
22 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction; | ||
23 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; | ||
24 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; | ||
25 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction; | ||
26 | +import org.onlab.onos.net.flow.instructions.L3ModificationInstruction; | ||
27 | +import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; | ||
28 | +import org.projectfloodlight.openflow.protocol.OFFactory; | ||
29 | +import org.projectfloodlight.openflow.protocol.OFFlowMod; | ||
30 | +import org.projectfloodlight.openflow.protocol.OFFlowModFlags; | ||
31 | +import org.projectfloodlight.openflow.protocol.action.OFAction; | ||
32 | +import org.projectfloodlight.openflow.protocol.match.Match; | ||
33 | +import org.projectfloodlight.openflow.protocol.match.MatchField; | ||
34 | +import org.projectfloodlight.openflow.types.EthType; | ||
35 | +import org.projectfloodlight.openflow.types.IPv4Address; | ||
36 | +import org.projectfloodlight.openflow.types.IpProtocol; | ||
37 | +import org.projectfloodlight.openflow.types.MacAddress; | ||
38 | +import org.projectfloodlight.openflow.types.Masked; | ||
39 | +import org.projectfloodlight.openflow.types.OFBufferId; | ||
40 | +import org.projectfloodlight.openflow.types.OFPort; | ||
41 | +import org.projectfloodlight.openflow.types.OFVlanVidMatch; | ||
42 | +import org.projectfloodlight.openflow.types.VlanPcp; | ||
43 | +import org.projectfloodlight.openflow.types.VlanVid; | ||
44 | +import org.slf4j.Logger; | ||
45 | + | ||
46 | + | ||
47 | +public class FlowModBuilder { | ||
48 | + | ||
49 | + private final Logger log = getLogger(getClass()); | ||
50 | + | ||
51 | + private final OFFactory factory; | ||
52 | + private final TrafficTreatment treatment; | ||
53 | + private final TrafficSelector selector; | ||
54 | + | ||
55 | + private final int priority; | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + public FlowModBuilder(FlowRule flowRule, OFFactory factory) { | ||
60 | + this.factory = factory; | ||
61 | + this.treatment = flowRule.treatment(); | ||
62 | + this.selector = flowRule.selector(); | ||
63 | + this.priority = flowRule.priority(); | ||
64 | + } | ||
65 | + | ||
66 | + public OFFlowMod buildFlowMod() { | ||
67 | + Match match = buildMatch(); | ||
68 | + List<OFAction> actions = buildActions(); | ||
69 | + | ||
70 | + //TODO: what to do without bufferid? do we assume that there will be a pktout as well? | ||
71 | + OFFlowMod fm = factory.buildFlowModify() | ||
72 | + .setBufferId(OFBufferId.NO_BUFFER) | ||
73 | + .setActions(actions) | ||
74 | + .setMatch(match) | ||
75 | + .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) | ||
76 | + .setIdleTimeout(10) | ||
77 | + .setHardTimeout(10) | ||
78 | + .setPriority(priority) | ||
79 | + .build(); | ||
80 | + | ||
81 | + return fm; | ||
82 | + | ||
83 | + } | ||
84 | + | ||
85 | + private List<OFAction> buildActions() { | ||
86 | + List<OFAction> acts = new LinkedList<>(); | ||
87 | + for (Instruction i : treatment.instructions()) { | ||
88 | + switch (i.type()) { | ||
89 | + case DROP: | ||
90 | + log.warn("Saw drop action; assigning drop action"); | ||
91 | + return new LinkedList<>(); | ||
92 | + case L2MODIFICATION: | ||
93 | + acts.add(buildL2Modification(i)); | ||
94 | + case L3MODIFICATION: | ||
95 | + acts.add(buildL3Modification(i)); | ||
96 | + case OUTPUT: | ||
97 | + OutputInstruction out = (OutputInstruction) i; | ||
98 | + acts.add(factory.actions().buildOutput().setPort( | ||
99 | + OFPort.of((int) out.port().toLong())).build()); | ||
100 | + break; | ||
101 | + case GROUP: | ||
102 | + default: | ||
103 | + log.warn("Instruction type {} not yet implemented.", i.type()); | ||
104 | + } | ||
105 | + } | ||
106 | + | ||
107 | + return acts; | ||
108 | + } | ||
109 | + | ||
110 | + private OFAction buildL3Modification(Instruction i) { | ||
111 | + L3ModificationInstruction l3m = (L3ModificationInstruction) i; | ||
112 | + ModIPInstruction ip; | ||
113 | + switch (l3m.subtype()) { | ||
114 | + case L3_DST: | ||
115 | + ip = (ModIPInstruction) i; | ||
116 | + return factory.actions().setNwDst(IPv4Address.of(ip.ip().toInt())); | ||
117 | + case L3_SRC: | ||
118 | + ip = (ModIPInstruction) i; | ||
119 | + return factory.actions().setNwSrc(IPv4Address.of(ip.ip().toInt())); | ||
120 | + default: | ||
121 | + log.warn("Unimplemented action type {}.", l3m.subtype()); | ||
122 | + break; | ||
123 | + } | ||
124 | + return null; | ||
125 | + } | ||
126 | + | ||
127 | + private OFAction buildL2Modification(Instruction i) { | ||
128 | + L2ModificationInstruction l2m = (L2ModificationInstruction) i; | ||
129 | + ModEtherInstruction eth; | ||
130 | + switch (l2m.subtype()) { | ||
131 | + case L2_DST: | ||
132 | + eth = (ModEtherInstruction) l2m; | ||
133 | + return factory.actions().setDlDst(MacAddress.of(eth.mac().toLong())); | ||
134 | + case L2_SRC: | ||
135 | + eth = (ModEtherInstruction) l2m; | ||
136 | + return factory.actions().setDlSrc(MacAddress.of(eth.mac().toLong())); | ||
137 | + case VLAN_ID: | ||
138 | + ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; | ||
139 | + return factory.actions().setVlanVid(VlanVid.ofVlan(vlanId.vlanId.toShort())); | ||
140 | + case VLAN_PCP: | ||
141 | + ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; | ||
142 | + return factory.actions().setVlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); | ||
143 | + default: | ||
144 | + log.warn("Unimplemented action type {}.", l2m.subtype()); | ||
145 | + break; | ||
146 | + } | ||
147 | + return null; | ||
148 | + } | ||
149 | + | ||
150 | + private Match buildMatch() { | ||
151 | + Match.Builder mBuilder = factory.buildMatch(); | ||
152 | + EthCriterion eth; | ||
153 | + IPCriterion ip; | ||
154 | + for (Criterion c : selector.criteria()) { | ||
155 | + switch (c.type()) { | ||
156 | + case IN_PORT: | ||
157 | + PortCriterion inport = (PortCriterion) c; | ||
158 | + mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inport.port().toLong())); | ||
159 | + break; | ||
160 | + case ETH_SRC: | ||
161 | + eth = (EthCriterion) c; | ||
162 | + mBuilder.setExact(MatchField.ETH_SRC, MacAddress.of(eth.mac().toLong())); | ||
163 | + break; | ||
164 | + case ETH_DST: | ||
165 | + eth = (EthCriterion) c; | ||
166 | + mBuilder.setExact(MatchField.ETH_DST, MacAddress.of(eth.mac().toLong())); | ||
167 | + break; | ||
168 | + case ETH_TYPE: | ||
169 | + EthTypeCriterion ethType = (EthTypeCriterion) c; | ||
170 | + mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType())); | ||
171 | + break; | ||
172 | + case IPV4_DST: | ||
173 | + ip = (IPCriterion) c; | ||
174 | + if (ip.ip().isMasked()) { | ||
175 | + Masked<IPv4Address> maskedIp = Masked.of(IPv4Address.of(ip.ip().toInt()), | ||
176 | + IPv4Address.of(ip.ip().netmask().toInt())); | ||
177 | + mBuilder.setMasked(MatchField.IPV4_DST, maskedIp); | ||
178 | + } else { | ||
179 | + mBuilder.setExact(MatchField.IPV4_DST, IPv4Address.of(ip.ip().toInt())); | ||
180 | + } | ||
181 | + break; | ||
182 | + case IPV4_SRC: | ||
183 | + ip = (IPCriterion) c; | ||
184 | + if (ip.ip().isMasked()) { | ||
185 | + Masked<IPv4Address> maskedIp = Masked.of(IPv4Address.of(ip.ip().toInt()), | ||
186 | + IPv4Address.of(ip.ip().netmask().toInt())); | ||
187 | + mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp); | ||
188 | + } else { | ||
189 | + mBuilder.setExact(MatchField.IPV4_SRC, IPv4Address.of(ip.ip().toInt())); | ||
190 | + } | ||
191 | + break; | ||
192 | + case IP_PROTO: | ||
193 | + IPProtocolCriterion p = (IPProtocolCriterion) c; | ||
194 | + mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol())); | ||
195 | + break; | ||
196 | + case VLAN_PCP: | ||
197 | + VlanPcpCriterion vpcp = (VlanPcpCriterion) c; | ||
198 | + mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority())); | ||
199 | + break; | ||
200 | + case VLAN_VID: | ||
201 | + VlanIdCriterion vid = (VlanIdCriterion) c; | ||
202 | + mBuilder.setExact(MatchField.VLAN_VID, | ||
203 | + OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort()))); | ||
204 | + break; | ||
205 | + case ARP_OP: | ||
206 | + case ARP_SHA: | ||
207 | + case ARP_SPA: | ||
208 | + case ARP_THA: | ||
209 | + case ARP_TPA: | ||
210 | + case ICMPV4_CODE: | ||
211 | + case ICMPV4_TYPE: | ||
212 | + case ICMPV6_CODE: | ||
213 | + case ICMPV6_TYPE: | ||
214 | + case IN_PHY_PORT: | ||
215 | + case IPV6_DST: | ||
216 | + case IPV6_EXTHDR: | ||
217 | + case IPV6_FLABEL: | ||
218 | + case IPV6_ND_SLL: | ||
219 | + case IPV6_ND_TARGET: | ||
220 | + case IPV6_ND_TLL: | ||
221 | + case IPV6_SRC: | ||
222 | + case IP_DSCP: | ||
223 | + case IP_ECN: | ||
224 | + case METADATA: | ||
225 | + case MPLS_BOS: | ||
226 | + case MPLS_LABEL: | ||
227 | + case MPLS_TC: | ||
228 | + case PBB_ISID: | ||
229 | + case SCTP_DST: | ||
230 | + case SCTP_SRC: | ||
231 | + case TCP_DST: | ||
232 | + case TCP_SRC: | ||
233 | + case TUNNEL_ID: | ||
234 | + case UDP_DST: | ||
235 | + case UDP_SRC: | ||
236 | + default: | ||
237 | + log.warn("Match type {} not yet implemented.", c.type()); | ||
238 | + } | ||
239 | + } | ||
240 | + return mBuilder.build(); | ||
241 | + } | ||
242 | + | ||
243 | +} |
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowStatsCollector.java
0 → 100644
1 | +package org.onlab.onos.provider.of.flow.impl; | ||
2 | + | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
5 | +import java.util.concurrent.TimeUnit; | ||
6 | + | ||
7 | +import org.jboss.netty.util.HashedWheelTimer; | ||
8 | +import org.jboss.netty.util.Timeout; | ||
9 | +import org.jboss.netty.util.TimerTask; | ||
10 | +import org.onlab.onos.openflow.controller.OpenFlowSwitch; | ||
11 | +import org.onlab.util.Timer; | ||
12 | +import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest; | ||
13 | +import org.projectfloodlight.openflow.types.OFPort; | ||
14 | +import org.projectfloodlight.openflow.types.TableId; | ||
15 | +import org.slf4j.Logger; | ||
16 | + | ||
17 | +public class FlowStatsCollector implements TimerTask { | ||
18 | + | ||
19 | + private final Logger log = getLogger(getClass()); | ||
20 | + | ||
21 | + private final HashedWheelTimer timer = Timer.getTimer(); | ||
22 | + private final OpenFlowSwitch sw; | ||
23 | + private final int refreshInterval; | ||
24 | + | ||
25 | + private Timeout timeout; | ||
26 | + | ||
27 | + private boolean stopTimer = false;; | ||
28 | + | ||
29 | + public FlowStatsCollector(OpenFlowSwitch sw, int refreshInterval) { | ||
30 | + this.sw = sw; | ||
31 | + this.refreshInterval = refreshInterval; | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + public void run(Timeout timeout) throws Exception { | ||
36 | + log.debug("Collecting stats for {}", this.sw.getStringId()); | ||
37 | + | ||
38 | + sendFlowStatistics(); | ||
39 | + | ||
40 | + if (!this.stopTimer) { | ||
41 | + log.debug("Scheduling stats collection in {} seconds for {}", | ||
42 | + this.refreshInterval, this.sw.getStringId()); | ||
43 | + timeout.getTimer().newTimeout(this, refreshInterval, | ||
44 | + TimeUnit.SECONDS); | ||
45 | + } | ||
46 | + | ||
47 | + | ||
48 | + } | ||
49 | + | ||
50 | + private void sendFlowStatistics() { | ||
51 | + OFFlowStatsRequest request = sw.factory().buildFlowStatsRequest() | ||
52 | + .setMatch(sw.factory().matchWildcardAll()) | ||
53 | + .setTableId(TableId.ALL) | ||
54 | + .setOutPort(OFPort.NO_MASK) | ||
55 | + .build(); | ||
56 | + | ||
57 | + this.sw.sendMsg(request); | ||
58 | + | ||
59 | + } | ||
60 | + | ||
61 | + public void start() { | ||
62 | + | ||
63 | + /* | ||
64 | + * Initially start polling quickly. Then drop down to configured value | ||
65 | + */ | ||
66 | + log.info("Starting Stats collection thread for {}", | ||
67 | + this.sw.getStringId()); | ||
68 | + timeout = timer.newTimeout(this, 1, TimeUnit.SECONDS); | ||
69 | + } | ||
70 | + | ||
71 | + public void stop() { | ||
72 | + log.info("Stopping Stats collection thread for {}", | ||
73 | + this.sw.getStringId()); | ||
74 | + this.stopTimer = true; | ||
75 | + timeout.cancel(); | ||
76 | + } | ||
77 | + | ||
78 | +} |
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java
... | @@ -2,9 +2,7 @@ package org.onlab.onos.provider.of.flow.impl; | ... | @@ -2,9 +2,7 @@ package org.onlab.onos.provider.of.flow.impl; |
2 | 2 | ||
3 | import static org.slf4j.LoggerFactory.getLogger; | 3 | import static org.slf4j.LoggerFactory.getLogger; |
4 | 4 | ||
5 | -import java.util.Collections; | 5 | +import java.util.Map; |
6 | -import java.util.LinkedList; | ||
7 | -import java.util.List; | ||
8 | 6 | ||
9 | import org.apache.felix.scr.annotations.Activate; | 7 | import org.apache.felix.scr.annotations.Activate; |
10 | import org.apache.felix.scr.annotations.Component; | 8 | import org.apache.felix.scr.annotations.Component; |
... | @@ -12,50 +10,27 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -12,50 +10,27 @@ import org.apache.felix.scr.annotations.Deactivate; |
12 | import org.apache.felix.scr.annotations.Reference; | 10 | import org.apache.felix.scr.annotations.Reference; |
13 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 11 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
14 | import org.onlab.onos.net.DeviceId; | 12 | import org.onlab.onos.net.DeviceId; |
13 | +import org.onlab.onos.net.flow.DefaultFlowRule; | ||
15 | import org.onlab.onos.net.flow.FlowEntry; | 14 | import org.onlab.onos.net.flow.FlowEntry; |
16 | import org.onlab.onos.net.flow.FlowRule; | 15 | import org.onlab.onos.net.flow.FlowRule; |
17 | import org.onlab.onos.net.flow.FlowRuleProvider; | 16 | import org.onlab.onos.net.flow.FlowRuleProvider; |
18 | import org.onlab.onos.net.flow.FlowRuleProviderRegistry; | 17 | import org.onlab.onos.net.flow.FlowRuleProviderRegistry; |
19 | import org.onlab.onos.net.flow.FlowRuleProviderService; | 18 | import org.onlab.onos.net.flow.FlowRuleProviderService; |
20 | -import org.onlab.onos.net.flow.criteria.Criteria.EthCriterion; | ||
21 | -import org.onlab.onos.net.flow.criteria.Criteria.EthTypeCriterion; | ||
22 | -import org.onlab.onos.net.flow.criteria.Criteria.IPCriterion; | ||
23 | -import org.onlab.onos.net.flow.criteria.Criteria.IPProtocolCriterion; | ||
24 | -import org.onlab.onos.net.flow.criteria.Criteria.PortCriterion; | ||
25 | -import org.onlab.onos.net.flow.criteria.Criteria.VlanIdCriterion; | ||
26 | -import org.onlab.onos.net.flow.criteria.Criteria.VlanPcpCriterion; | ||
27 | -import org.onlab.onos.net.flow.criteria.Criterion; | ||
28 | -import org.onlab.onos.net.flow.instructions.Instruction; | ||
29 | -import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction; | ||
30 | -import org.onlab.onos.net.flow.instructions.L2ModificationInstruction; | ||
31 | -import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; | ||
32 | -import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; | ||
33 | -import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction; | ||
34 | -import org.onlab.onos.net.flow.instructions.L3ModificationInstruction; | ||
35 | -import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; | ||
36 | import org.onlab.onos.net.provider.AbstractProvider; | 19 | import org.onlab.onos.net.provider.AbstractProvider; |
37 | import org.onlab.onos.net.provider.ProviderId; | 20 | import org.onlab.onos.net.provider.ProviderId; |
38 | import org.onlab.onos.net.topology.TopologyService; | 21 | import org.onlab.onos.net.topology.TopologyService; |
39 | import org.onlab.onos.openflow.controller.Dpid; | 22 | import org.onlab.onos.openflow.controller.Dpid; |
40 | import org.onlab.onos.openflow.controller.OpenFlowController; | 23 | import org.onlab.onos.openflow.controller.OpenFlowController; |
24 | +import org.onlab.onos.openflow.controller.OpenFlowEventListener; | ||
41 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; | 25 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; |
42 | -import org.projectfloodlight.openflow.protocol.OFFactory; | 26 | +import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; |
43 | -import org.projectfloodlight.openflow.protocol.OFFlowMod; | 27 | +import org.projectfloodlight.openflow.protocol.OFFlowRemoved; |
44 | -import org.projectfloodlight.openflow.protocol.OFFlowModFlags; | 28 | +import org.projectfloodlight.openflow.protocol.OFMessage; |
45 | -import org.projectfloodlight.openflow.protocol.action.OFAction; | 29 | +import org.projectfloodlight.openflow.protocol.OFPortStatus; |
46 | -import org.projectfloodlight.openflow.protocol.match.Match; | ||
47 | -import org.projectfloodlight.openflow.protocol.match.MatchField; | ||
48 | -import org.projectfloodlight.openflow.types.EthType; | ||
49 | -import org.projectfloodlight.openflow.types.IPv4Address; | ||
50 | -import org.projectfloodlight.openflow.types.IpProtocol; | ||
51 | -import org.projectfloodlight.openflow.types.MacAddress; | ||
52 | -import org.projectfloodlight.openflow.types.OFBufferId; | ||
53 | -import org.projectfloodlight.openflow.types.OFPort; | ||
54 | -import org.projectfloodlight.openflow.types.OFVlanVidMatch; | ||
55 | -import org.projectfloodlight.openflow.types.VlanPcp; | ||
56 | -import org.projectfloodlight.openflow.types.VlanVid; | ||
57 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
58 | 31 | ||
32 | +import com.google.common.collect.Maps; | ||
33 | + | ||
59 | /** | 34 | /** |
60 | * Provider which uses an OpenFlow controller to detect network | 35 | * Provider which uses an OpenFlow controller to detect network |
61 | * end-station hosts. | 36 | * end-station hosts. |
... | @@ -76,6 +51,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -76,6 +51,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
76 | 51 | ||
77 | private FlowRuleProviderService providerService; | 52 | private FlowRuleProviderService providerService; |
78 | 53 | ||
54 | + private final InternalFlowProvider listener = new InternalFlowProvider(); | ||
55 | + | ||
79 | /** | 56 | /** |
80 | * Creates an OpenFlow host provider. | 57 | * Creates an OpenFlow host provider. |
81 | */ | 58 | */ |
... | @@ -86,6 +63,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -86,6 +63,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
86 | @Activate | 63 | @Activate |
87 | public void activate() { | 64 | public void activate() { |
88 | providerService = providerRegistry.register(this); | 65 | providerService = providerRegistry.register(this); |
66 | + controller.addListener(listener); | ||
67 | + controller.addEventListener(listener); | ||
89 | log.info("Started"); | 68 | log.info("Started"); |
90 | } | 69 | } |
91 | 70 | ||
... | @@ -105,168 +84,10 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -105,168 +84,10 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
105 | 84 | ||
106 | private void applyRule(FlowRule flowRule) { | 85 | private void applyRule(FlowRule flowRule) { |
107 | OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); | 86 | OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); |
108 | - Match match = buildMatch(flowRule.selector().criteria(), sw.factory()); | 87 | + sw.sendMsg(new FlowModBuilder(flowRule, sw.factory()).buildFlowMod()); |
109 | - List<OFAction> actions = | ||
110 | - buildActions(flowRule.treatment().instructions(), sw.factory()); | ||
111 | - | ||
112 | - //TODO: what to do without bufferid? do we assume that there will be a pktout as well? | ||
113 | - OFFlowMod fm = sw.factory().buildFlowModify() | ||
114 | - .setBufferId(OFBufferId.NO_BUFFER) | ||
115 | - .setActions(actions) | ||
116 | - .setMatch(match) | ||
117 | - .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) | ||
118 | - .setIdleTimeout(10) | ||
119 | - .setHardTimeout(10) | ||
120 | - .setPriority(flowRule.priority()) | ||
121 | - .build(); | ||
122 | - sw.sendMsg(fm); | ||
123 | - } | ||
124 | - | ||
125 | - private List<OFAction> buildActions(List<Instruction> instructions, OFFactory factory) { | ||
126 | - List<OFAction> acts = new LinkedList<>(); | ||
127 | - for (Instruction i : instructions) { | ||
128 | - switch (i.type()) { | ||
129 | - case DROP: | ||
130 | - log.warn("Saw drop action; assigning drop action"); | ||
131 | - return new LinkedList<>(); | ||
132 | - case L2MODIFICATION: | ||
133 | - acts.add(buildL2Modification(i, factory)); | ||
134 | - case L3MODIFICATION: | ||
135 | - acts.add(buildL3Modification(i, factory)); | ||
136 | - case OUTPUT: | ||
137 | - OutputInstruction out = (OutputInstruction) i; | ||
138 | - acts.add(factory.actions().buildOutput().setPort( | ||
139 | - OFPort.of((int) out.port().toLong())).build()); | ||
140 | - break; | ||
141 | - case GROUP: | ||
142 | - default: | ||
143 | - log.warn("Instruction type {} not yet implemented.", i.type()); | ||
144 | - } | ||
145 | } | 88 | } |
146 | 89 | ||
147 | - return acts; | ||
148 | - } | ||
149 | - | ||
150 | - private OFAction buildL3Modification(Instruction i, OFFactory factory) { | ||
151 | - L3ModificationInstruction l3m = (L3ModificationInstruction) i; | ||
152 | - ModIPInstruction ip; | ||
153 | - switch (l3m.subtype()) { | ||
154 | - case L3_DST: | ||
155 | - ip = (ModIPInstruction) i; | ||
156 | - return factory.actions().setNwDst(IPv4Address.of(ip.ip().toInt())); | ||
157 | - case L3_SRC: | ||
158 | - ip = (ModIPInstruction) i; | ||
159 | - return factory.actions().setNwSrc(IPv4Address.of(ip.ip().toInt())); | ||
160 | - default: | ||
161 | - log.warn("Unimplemented action type {}.", l3m.subtype()); | ||
162 | - break; | ||
163 | - } | ||
164 | - return null; | ||
165 | - } | ||
166 | 90 | ||
167 | - private OFAction buildL2Modification(Instruction i, OFFactory factory) { | ||
168 | - L2ModificationInstruction l2m = (L2ModificationInstruction) i; | ||
169 | - ModEtherInstruction eth; | ||
170 | - switch (l2m.subtype()) { | ||
171 | - case L2_DST: | ||
172 | - eth = (ModEtherInstruction) l2m; | ||
173 | - return factory.actions().setDlDst(MacAddress.of(eth.mac().toLong())); | ||
174 | - case L2_SRC: | ||
175 | - eth = (ModEtherInstruction) l2m; | ||
176 | - return factory.actions().setDlSrc(MacAddress.of(eth.mac().toLong())); | ||
177 | - case VLAN_ID: | ||
178 | - ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; | ||
179 | - return factory.actions().setVlanVid(VlanVid.ofVlan(vlanId.vlanId.toShort())); | ||
180 | - case VLAN_PCP: | ||
181 | - ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; | ||
182 | - return factory.actions().setVlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); | ||
183 | - default: | ||
184 | - log.warn("Unimplemented action type {}.", l2m.subtype()); | ||
185 | - break; | ||
186 | - } | ||
187 | - return null; | ||
188 | - } | ||
189 | - | ||
190 | - private Match buildMatch(List<Criterion> criteria, OFFactory factory) { | ||
191 | - Match.Builder mBuilder = factory.buildMatch(); | ||
192 | - EthCriterion eth; | ||
193 | - IPCriterion ip; | ||
194 | - for (Criterion c : criteria) { | ||
195 | - switch (c.type()) { | ||
196 | - case IN_PORT: | ||
197 | - PortCriterion inport = (PortCriterion) c; | ||
198 | - mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inport.port().toLong())); | ||
199 | - break; | ||
200 | - case ETH_SRC: | ||
201 | - eth = (EthCriterion) c; | ||
202 | - mBuilder.setExact(MatchField.ETH_SRC, MacAddress.of(eth.mac().toLong())); | ||
203 | - break; | ||
204 | - case ETH_DST: | ||
205 | - eth = (EthCriterion) c; | ||
206 | - mBuilder.setExact(MatchField.ETH_DST, MacAddress.of(eth.mac().toLong())); | ||
207 | - break; | ||
208 | - case ETH_TYPE: | ||
209 | - EthTypeCriterion ethType = (EthTypeCriterion) c; | ||
210 | - mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType())); | ||
211 | - break; | ||
212 | - case IPV4_DST: | ||
213 | - ip = (IPCriterion) c; | ||
214 | - mBuilder.setExact(MatchField.IPV4_DST, IPv4Address.of(ip.ip().toInt())); | ||
215 | - break; | ||
216 | - case IPV4_SRC: | ||
217 | - ip = (IPCriterion) c; | ||
218 | - mBuilder.setExact(MatchField.IPV4_SRC, IPv4Address.of(ip.ip().toInt())); | ||
219 | - break; | ||
220 | - case IP_PROTO: | ||
221 | - IPProtocolCriterion p = (IPProtocolCriterion) c; | ||
222 | - mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol())); | ||
223 | - break; | ||
224 | - case VLAN_PCP: | ||
225 | - VlanPcpCriterion vpcp = (VlanPcpCriterion) c; | ||
226 | - mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority())); | ||
227 | - break; | ||
228 | - case VLAN_VID: | ||
229 | - VlanIdCriterion vid = (VlanIdCriterion) c; | ||
230 | - mBuilder.setExact(MatchField.VLAN_VID, | ||
231 | - OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort()))); | ||
232 | - break; | ||
233 | - case ARP_OP: | ||
234 | - case ARP_SHA: | ||
235 | - case ARP_SPA: | ||
236 | - case ARP_THA: | ||
237 | - case ARP_TPA: | ||
238 | - case ICMPV4_CODE: | ||
239 | - case ICMPV4_TYPE: | ||
240 | - case ICMPV6_CODE: | ||
241 | - case ICMPV6_TYPE: | ||
242 | - case IN_PHY_PORT: | ||
243 | - case IPV6_DST: | ||
244 | - case IPV6_EXTHDR: | ||
245 | - case IPV6_FLABEL: | ||
246 | - case IPV6_ND_SLL: | ||
247 | - case IPV6_ND_TARGET: | ||
248 | - case IPV6_ND_TLL: | ||
249 | - case IPV6_SRC: | ||
250 | - case IP_DSCP: | ||
251 | - case IP_ECN: | ||
252 | - case METADATA: | ||
253 | - case MPLS_BOS: | ||
254 | - case MPLS_LABEL: | ||
255 | - case MPLS_TC: | ||
256 | - case PBB_ISID: | ||
257 | - case SCTP_DST: | ||
258 | - case SCTP_SRC: | ||
259 | - case TCP_DST: | ||
260 | - case TCP_SRC: | ||
261 | - case TUNNEL_ID: | ||
262 | - case UDP_DST: | ||
263 | - case UDP_SRC: | ||
264 | - default: | ||
265 | - log.warn("Action type {} not yet implemented.", c.type()); | ||
266 | - } | ||
267 | - } | ||
268 | - return mBuilder.build(); | ||
269 | - } | ||
270 | 91 | ||
271 | @Override | 92 | @Override |
272 | public void removeFlowRule(FlowRule... flowRules) { | 93 | public void removeFlowRule(FlowRule... flowRules) { |
... | @@ -283,6 +104,49 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -283,6 +104,49 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
283 | 104 | ||
284 | //TODO: InternalFlowRuleProvider listening to stats and error and flowremoved. | 105 | //TODO: InternalFlowRuleProvider listening to stats and error and flowremoved. |
285 | // possibly barriers as well. May not be internal at all... | 106 | // possibly barriers as well. May not be internal at all... |
107 | + private class InternalFlowProvider | ||
108 | + implements OpenFlowSwitchListener, OpenFlowEventListener { | ||
109 | + | ||
110 | + private final Map<Dpid, FlowStatsCollector> collectors = Maps.newHashMap(); | ||
111 | + | ||
112 | + @Override | ||
113 | + public void switchAdded(Dpid dpid) { | ||
114 | + FlowStatsCollector fsc = new FlowStatsCollector(controller.getSwitch(dpid), 1); | ||
115 | + fsc.start(); | ||
116 | + collectors.put(dpid, fsc); | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
120 | + public void switchRemoved(Dpid dpid) { | ||
121 | + collectors.remove(dpid).stop(); | ||
122 | + | ||
123 | + } | ||
124 | + | ||
125 | + @Override | ||
126 | + public void portChanged(Dpid dpid, OFPortStatus status) { | ||
127 | + //TODO: Decide whether to evict flows internal store. | ||
128 | + } | ||
129 | + | ||
130 | + @Override | ||
131 | + public void handleMessage(Dpid dpid, OFMessage msg) { | ||
132 | + switch (msg.getType()) { | ||
133 | + case FLOW_REMOVED: | ||
134 | + //TODO: make this better | ||
135 | + OFFlowRemoved removed = (OFFlowRemoved) msg; | ||
136 | + FlowRule fr = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), null, null); | ||
137 | + providerService.flowRemoved(fr); | ||
138 | + break; | ||
139 | + case STATS_REPLY: | ||
140 | + break; | ||
141 | + case BARRIER_REPLY: | ||
142 | + case ERROR: | ||
143 | + default: | ||
144 | + log.warn("Unhandled message type: {}", msg.getType()); | ||
145 | + } | ||
146 | + | ||
147 | + } | ||
148 | + | ||
149 | + } | ||
286 | 150 | ||
287 | 151 | ||
288 | } | 152 | } | ... | ... |
... | @@ -46,7 +46,7 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext { | ... | @@ -46,7 +46,7 @@ public class OpenFlowCorePacketContext extends DefaultPacketContext { |
46 | private void sendBufferedPacket() { | 46 | private void sendBufferedPacket() { |
47 | List<Instruction> ins = treatmentBuilder().build().instructions(); | 47 | List<Instruction> ins = treatmentBuilder().build().instructions(); |
48 | OFPort p = null; | 48 | OFPort p = null; |
49 | - //TODO: support arbitrary list of treatments | 49 | + //TODO: support arbitrary list of treatments must be supported in ofPacketContext |
50 | for (Instruction i : ins) { | 50 | for (Instruction i : ins) { |
51 | if (i.type() == Type.OUTPUT) { | 51 | if (i.type() == Type.OUTPUT) { |
52 | p = buildPort(((OutputInstruction) i).port()); | 52 | p = buildPort(((OutputInstruction) i).port()); | ... | ... |
tools/build/envDefaults
0 → 100644
1 | +# Environmental defaults for ONOS build, package and test | ||
2 | + | ||
3 | +# Root of the ONOS source tree | ||
4 | +export ONOS_ROOT=${ONOS_ROOT:-~/onos-next} | ||
5 | + | ||
6 | +# M2 repository and Karaf gold bits | ||
7 | +export M2_REPO=${M2_REPO:-~/.m2/repository} | ||
8 | +export KARAF_ZIP=${KARAF_ZIP:-~/Downloads/apache-karaf-3.0.1.zip} | ||
9 | +export KARAF_DIST=$(basename $KARAF_ZIP .zip) | ||
10 | + | ||
11 | +# ONOS Version and onos.tar.gz staging environment | ||
12 | +export ONOS_VERSION=${ONOS_VERSION:-1.0.0-SNAPSHOT} | ||
13 | +export ONOS_STAGE_ROOT=${ONOS_STAGE_ROOT:-/tmp} | ||
14 | +export ONOS_BITS=onos-$ONOS_VERSION | ||
15 | +export ONOS_STAGE=$ONOS_STAGE_ROOT/$ONOS_BITS | ||
16 | +export ONOS_TAR=$ONOS_STAGE.tar.gz | ||
17 | + | ||
18 | +# Defaults for ONOS testing using remote machines. | ||
19 | +export ONOS_INSTALL_DIR="/opt/onos" # Installation directory on remote | ||
20 | +export OCI="${OCI:-192.168.56.101}" # ONOS Controller Instance | ||
21 | +export ONOS_USER="sdn" # ONOS user on remote system | ||
22 | +export ONOS_PWD="rocks" # ONOS user password on remote system |
... | @@ -3,14 +3,8 @@ | ... | @@ -3,14 +3,8 @@ |
3 | # Packages ONOS distributable into onos.tar.gz | 3 | # Packages ONOS distributable into onos.tar.gz |
4 | #------------------------------------------------------------------------------- | 4 | #------------------------------------------------------------------------------- |
5 | 5 | ||
6 | -export M2_REPO=${M2_REPO:-~/.m2/repository} | 6 | +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
7 | -export KARAF_ZIP=${KARAF_ZIP:-~/Downloads/apache-karaf-3.0.1.zip} | 7 | +. $ONOS_ROOT/tools/build/envDefaults |
8 | -export KARAF_DIST=$(basename $KARAF_ZIP .zip) | ||
9 | - | ||
10 | -export ONOS_VERSION=${ONOS_VERSION:-1.0.0-SNAPSHOT} | ||
11 | -export ONOS_STAGE_ROOT=${ONOS_STAGE_ROOT:-/tmp} | ||
12 | -export ONOS_BITS=onos-$ONOS_VERSION | ||
13 | -export ONOS_STAGE=$ONOS_STAGE_ROOT/$ONOS_BITS | ||
14 | 8 | ||
15 | # Bail on any errors | 9 | # Bail on any errors |
16 | set -e | 10 | set -e |
... | @@ -26,29 +20,31 @@ rm -fr $ONOS_STAGE # Remove this when package script is completed | ... | @@ -26,29 +20,31 @@ rm -fr $ONOS_STAGE # Remove this when package script is completed |
26 | mkdir -p $ONOS_STAGE | 20 | mkdir -p $ONOS_STAGE |
27 | cd $ONOS_STAGE | 21 | cd $ONOS_STAGE |
28 | 22 | ||
29 | -# Unroll the Apache Karaf bits and make the ONOS top-level directories. | 23 | +# Unroll the Apache Karaf bits, prune them and make ONOS top-level directories. |
30 | -unzip $KARAF_ZIP | 24 | +unzip -q $KARAF_ZIP && rm -rf $KARAF_DIST/demos |
31 | mkdir bin | 25 | mkdir bin |
32 | 26 | ||
33 | -# Stage the ONOS admin scripts | 27 | +# Stage the ONOS admin scripts and patch in Karaf service wrapper extras |
34 | cp -r $ONOS_ROOT/tools/package/bin . | 28 | cp -r $ONOS_ROOT/tools/package/bin . |
29 | +cp -r $ONOS_ROOT/tools/package/wrapper/* $KARAF_DIST | ||
35 | 30 | ||
36 | # Stage the ONOS bundles | 31 | # Stage the ONOS bundles |
37 | -mkdir -p system/org/onlab | 32 | +mkdir -p $KARAF_DIST/system/org/onlab |
38 | -cp -r $M2_REPO/org/onlab system/org/ | 33 | +cp -r $M2_REPO/org/onlab $KARAF_DIST/system/org/ |
39 | 34 | ||
40 | # Patch the Apache Karaf distribution file to add ONOS features repository | 35 | # Patch the Apache Karaf distribution file to add ONOS features repository |
41 | perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onlab.onos/onos-features/$ONOS_VERSION/xml/features|" \ | 36 | perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onlab.onos/onos-features/$ONOS_VERSION/xml/features|" \ |
42 | $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg | 37 | $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg |
43 | 38 | ||
44 | # Patch the Apache Karaf distribution file to load ONOS features | 39 | # Patch the Apache Karaf distribution file to load ONOS features |
45 | -perl -pi.old -e 's|^(featuresBoot=.*)|\1,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-tvue|' \ | 40 | +perl -pi.old -e 's|^(featuresBoot=.*)|\1,wrapper,onos-api,onos-core,onos-cli,onos-rest,onos-gui,onos-openflow,onos-app-tvue|' \ |
46 | - /tmp/onos-1.0.0-SNAPSHOT/apache-karaf-3.0.1/etc/org.apache.karaf.features.cfg | 41 | + $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg |
47 | 42 | ||
48 | # Patch the Apache Karaf distribution with ONOS branding bundle | 43 | # Patch the Apache Karaf distribution with ONOS branding bundle |
49 | cp $M2_REPO/org/onlab/onos/onos-branding/$ONOS_VERSION/onos-branding-*.jar \ | 44 | cp $M2_REPO/org/onlab/onos/onos-branding/$ONOS_VERSION/onos-branding-*.jar \ |
50 | - $ONOS_STAGE/apache-karaf-*/lib | 45 | + $ONOS_STAGE/$KARAF_DIST/lib |
51 | 46 | ||
52 | # Now package up the ONOS tar file | 47 | # Now package up the ONOS tar file |
53 | cd $ONOS_STAGE_ROOT | 48 | cd $ONOS_STAGE_ROOT |
54 | -tar zcf $ONOS_BITS.tar.gz $ONOS_BITS | 49 | +COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS |
50 | +ls -l $ONOS_TAR >&2 | ... | ... |
... | @@ -12,7 +12,8 @@ export KARAF_LOG=$KARAF/data/log/karaf.log | ... | @@ -12,7 +12,8 @@ export KARAF_LOG=$KARAF/data/log/karaf.log |
12 | 12 | ||
13 | # Setup a path | 13 | # Setup a path |
14 | export PS=":" | 14 | export PS=":" |
15 | -export PATH="$PATH:$ONOS_ROOT/tools/dev:$ONOS_ROOT/tools/package" | 15 | +export PATH="$PATH:$ONOS_ROOT/tools/dev:$ONOS_ROOT/tools/build" |
16 | +export PATH="$PATH:$ONOS_ROOT/tools/test/bin" | ||
16 | export PATH="$PATH:$MAVEN/bin:$KARAF/bin" | 17 | export PATH="$PATH:$MAVEN/bin:$KARAF/bin" |
17 | export PATH="$PATH:." | 18 | export PATH="$PATH:." |
18 | 19 | ||
... | @@ -39,3 +40,13 @@ alias pp='python -m json.tool' | ... | @@ -39,3 +40,13 @@ alias pp='python -m json.tool' |
39 | # Short-hand to launch API docs and sample topology viewer GUI | 40 | # Short-hand to launch API docs and sample topology viewer GUI |
40 | alias docs='open $ONOS_ROOT/target/site/apidocs/index.html' | 41 | alias docs='open $ONOS_ROOT/target/site/apidocs/index.html' |
41 | alias gui='open http://localhost:8181/onos/tvue' | 42 | alias gui='open http://localhost:8181/onos/tvue' |
43 | + | ||
44 | + | ||
45 | +# Miscellaneous | ||
46 | +function spy { | ||
47 | + ps -ef | egrep "$@" | grep -v egrep | ||
48 | +} | ||
49 | + | ||
50 | +function nuke { | ||
51 | + spy | cut -c7-11 | xargs kill | ||
52 | +} | ... | ... |
tools/package/README
0 → 100644
1 | +Artifacts for packaging onos.tar.gz. |
tools/package/bin/onos
0 → 100755
1 | +#!/bin/bash | ||
2 | +#------------------------------------------------------------------------------- | ||
3 | +# ONOS command-line client | ||
4 | +#------------------------------------------------------------------------------- | ||
5 | + | ||
6 | +export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/ | ||
7 | + | ||
8 | +cd $(dirname $0)/../apache-karaf-*/bin | ||
9 | +./client -h localhost "$@" | ||
10 | + |
... | @@ -3,6 +3,8 @@ | ... | @@ -3,6 +3,8 @@ |
3 | # Starts ONOS Apache Karaf container | 3 | # Starts ONOS Apache Karaf container |
4 | #------------------------------------------------------------------------------- | 4 | #------------------------------------------------------------------------------- |
5 | 5 | ||
6 | +export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/ | ||
7 | + | ||
6 | cd $(dirname $0)/../apache-karaf-*/bin | 8 | cd $(dirname $0)/../apache-karaf-*/bin |
7 | ./karaf "$@" | 9 | ./karaf "$@" |
8 | 10 | ... | ... |
tools/package/wrapper/bin/onos-service
0 → 100755
1 | +#! /bin/sh | ||
2 | + | ||
3 | +# ------------------------------------------------------------------------ | ||
4 | +# Licensed to the Apache Software Foundation (ASF) under one or more | ||
5 | +# contributor license agreements. See the NOTICE file distributed with | ||
6 | +# this work for additional information regarding copyright ownership. | ||
7 | +# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
8 | +# (the "License"); you may not use this file except in compliance with | ||
9 | +# the License. You may obtain a copy of the License at | ||
10 | +# | ||
11 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
12 | +# | ||
13 | +# Unless required by applicable law or agreed to in writing, software | ||
14 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
16 | +# See the License for the specific language governing permissions and | ||
17 | +# limitations under the License. | ||
18 | +# ------------------------------------------------------------------------ | ||
19 | + | ||
20 | +# If require, set the JAVA_HOME to launch the wrapper | ||
21 | +# | ||
22 | +#JAVA_HOME= | ||
23 | +# | ||
24 | + | ||
25 | +# Application | ||
26 | +APP_NAME="onos" | ||
27 | +APP_LONG_NAME="onos" | ||
28 | + | ||
29 | +# Wrapper | ||
30 | +WRAPPER_CMD="/opt/onos/apache-karaf-3.0.1/bin/${APP_NAME}-wrapper" | ||
31 | +WRAPPER_CONF="/opt/onos/apache-karaf-3.0.1/etc/${APP_NAME}-wrapper.conf" | ||
32 | + | ||
33 | +# Priority at which to run the wrapper. See "man nice" for valid priorities. | ||
34 | +# nice is only used if a priority is specified. | ||
35 | +PRIORITY= | ||
36 | + | ||
37 | +# Location of the data folder. | ||
38 | +DATADIR="/opt/onos/apache-karaf-3.0.1/data" | ||
39 | + | ||
40 | +# Location of the pid file. | ||
41 | +PIDDIR="/opt/onos/apache-karaf-3.0.1/data" | ||
42 | + | ||
43 | +# If uncommented, causes the Wrapper to be shutdown using an anchor file. | ||
44 | +# When launched with the 'start' command, it will also ignore all INT and | ||
45 | +# TERM signals. | ||
46 | +#IGNORE_SIGNALS=true | ||
47 | + | ||
48 | +# If specified, the Wrapper will be run as the specified user. | ||
49 | +# IMPORTANT - Make sure that the user has the required privileges to write | ||
50 | +# the PID file and wrapper.log files. Failure to be able to write the log | ||
51 | +# file will cause the Wrapper to exit without any way to write out an error | ||
52 | +# message. | ||
53 | +# NOTE - This will set the user which is used to run the Wrapper as well as | ||
54 | +# the JVM and is not useful in situations where a privileged resource or | ||
55 | +# port needs to be allocated prior to the user being changed. | ||
56 | +#RUN_AS_USER= | ||
57 | + | ||
58 | +# The following two lines are used by the chkconfig command. Change as is | ||
59 | +# appropriate for your application. They should remain commented. | ||
60 | +# chkconfig: 2345 20 80 | ||
61 | +# description: onos | ||
62 | + | ||
63 | +# Do not modify anything beyond this point | ||
64 | +#----------------------------------------------------------------------------- | ||
65 | + | ||
66 | +# Get the fully qualified path to the script | ||
67 | +case $0 in | ||
68 | + /*) | ||
69 | + SCRIPT="$0" | ||
70 | + ;; | ||
71 | + *) | ||
72 | + PWD=`pwd` | ||
73 | + SCRIPT="$PWD/$0" | ||
74 | + ;; | ||
75 | +esac | ||
76 | + | ||
77 | +# Resolve the true real path without any sym links. | ||
78 | +CHANGED=true | ||
79 | +while [ "X$CHANGED" != "X" ] | ||
80 | +do | ||
81 | + # Change spaces to ":" so the tokens can be parsed. | ||
82 | + SCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'` | ||
83 | + # Get the real path to this script, resolving any symbolic links | ||
84 | + TOKENS=`echo $SCRIPT | sed -e 's;/; ;g'` | ||
85 | + REALPATH= | ||
86 | + for C in $TOKENS; do | ||
87 | + REALPATH="$REALPATH/$C" | ||
88 | + while [ -h "$REALPATH" ] ; do | ||
89 | + LS="`ls -ld "$REALPATH"`" | ||
90 | + LINK="`expr "$LS" : '.*-> \(.*\)$'`" | ||
91 | + if expr "$LINK" : '/.*' > /dev/null; then | ||
92 | + REALPATH="$LINK" | ||
93 | + else | ||
94 | + REALPATH="`dirname "$REALPATH"`""/$LINK" | ||
95 | + fi | ||
96 | + done | ||
97 | + done | ||
98 | + # Change ":" chars back to spaces. | ||
99 | + REALPATH=`echo $REALPATH | sed -e 's;:; ;g'` | ||
100 | + | ||
101 | + if [ "$REALPATH" = "$SCRIPT" ] | ||
102 | + then | ||
103 | + CHANGED="" | ||
104 | + else | ||
105 | + SCRIPT="$REALPATH" | ||
106 | + fi | ||
107 | +done | ||
108 | + | ||
109 | +# Change the current directory to the location of the script | ||
110 | +cd "`dirname "$REALPATH"`" | ||
111 | +REALDIR=`pwd` | ||
112 | + | ||
113 | +# If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if | ||
114 | +# the working directory is later changed. | ||
115 | +FIRST_CHAR=`echo $PIDDIR | cut -c1,1` | ||
116 | +if [ "$FIRST_CHAR" != "/" ] | ||
117 | +then | ||
118 | + PIDDIR=$REALDIR/$PIDDIR | ||
119 | +fi | ||
120 | +# Same test for WRAPPER_CMD | ||
121 | +FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1` | ||
122 | +if [ "$FIRST_CHAR" != "/" ] | ||
123 | +then | ||
124 | + WRAPPER_CMD=$REALDIR/$WRAPPER_CMD | ||
125 | +fi | ||
126 | +# Same test for WRAPPER_CONF | ||
127 | +FIRST_CHAR=`echo $WRAPPER_CONF | cut -c1,1` | ||
128 | +if [ "$FIRST_CHAR" != "/" ] | ||
129 | +then | ||
130 | + WRAPPER_CONF=$REALDIR/$WRAPPER_CONF | ||
131 | +fi | ||
132 | + | ||
133 | +# Process ID | ||
134 | +ANCHORFILE="$PIDDIR/$APP_NAME.anchor" | ||
135 | +PIDFILE="$PIDDIR/$APP_NAME.pid" | ||
136 | +LOCKDIR="/var/lock/subsys" | ||
137 | +LOCKFILE="$LOCKDIR/$APP_NAME" | ||
138 | +pid="" | ||
139 | + | ||
140 | +# Resolve the location of the 'ps' command | ||
141 | +PSEXE="/usr/bin/ps" | ||
142 | +if [ ! -x $PSEXE ] | ||
143 | +then | ||
144 | + PSEXE="/bin/ps" | ||
145 | + if [ ! -x $PSEXE ] | ||
146 | + then | ||
147 | + echo "Unable to locate 'ps'." | ||
148 | + echo "Please report this message along with the location of the command on your system." | ||
149 | + exit 1 | ||
150 | + fi | ||
151 | +fi | ||
152 | + | ||
153 | +# Resolve the os | ||
154 | +DIST_OS=`uname -s | tr [:upper:] [:lower:] | tr -d [:blank:]` | ||
155 | +case "$DIST_OS" in | ||
156 | + 'sunos') | ||
157 | + DIST_OS="solaris" | ||
158 | + ;; | ||
159 | + 'hp-ux' | 'hp-ux64') | ||
160 | + DIST_OS="hpux" | ||
161 | + ;; | ||
162 | + 'darwin') | ||
163 | + DIST_OS="macosx" | ||
164 | + ;; | ||
165 | + 'unix_sv') | ||
166 | + DIST_OS="unixware" | ||
167 | + ;; | ||
168 | +esac | ||
169 | + | ||
170 | +# Resolve the architecture | ||
171 | +DIST_ARCH=`uname -p | tr [:upper:] [:lower:] | tr -d [:blank:]` | ||
172 | +if [ "$DIST_ARCH" = "unknown" ] | ||
173 | +then | ||
174 | + DIST_ARCH=`uname -m | tr [:upper:] [:lower:] | tr -d [:blank:]` | ||
175 | +fi | ||
176 | +case "$DIST_ARCH" in | ||
177 | + 'amd64' | 'ia32' | 'ia64' | 'i386' | 'i486' | 'i586' | 'i686' | 'x86_64') | ||
178 | + DIST_ARCH="x86" | ||
179 | + ;; | ||
180 | + 'ip27') | ||
181 | + DIST_ARCH="mips" | ||
182 | + ;; | ||
183 | + 'power' | 'powerpc' | 'power_pc' | 'ppc64') | ||
184 | + DIST_ARCH="ppc" | ||
185 | + ;; | ||
186 | + 'pa_risc' | 'pa-risc') | ||
187 | + DIST_ARCH="parisc" | ||
188 | + ;; | ||
189 | + 'sun4u' | 'sparcv9') | ||
190 | + DIST_ARCH="sparc" | ||
191 | + ;; | ||
192 | + '9000/800') | ||
193 | + DIST_ARCH="parisc" | ||
194 | + ;; | ||
195 | +esac | ||
196 | + | ||
197 | +# Decide on the wrapper binary to use. | ||
198 | +# If a 32-bit wrapper binary exists then it will work on 32 or 64 bit | ||
199 | +# platforms, if the 64-bit binary exists then the distribution most | ||
200 | +# likely wants to use long names. Otherwise, look for the default. | ||
201 | +# For macosx, we also want to look for universal binaries. | ||
202 | +WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" | ||
203 | +if [ -x $WRAPPER_TEST_CMD ] | ||
204 | +then | ||
205 | + WRAPPER_CMD="$WRAPPER_TEST_CMD" | ||
206 | +else | ||
207 | + if [ "$DIST_OS" = "macosx" ] | ||
208 | + then | ||
209 | + WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-universal-32" | ||
210 | + if [ -x $WRAPPER_TEST_CMD ] | ||
211 | + then | ||
212 | + WRAPPER_CMD="$WRAPPER_TEST_CMD" | ||
213 | + else | ||
214 | + WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64" | ||
215 | + if [ -x $WRAPPER_TEST_CMD ] | ||
216 | + then | ||
217 | + WRAPPER_CMD="$WRAPPER_TEST_CMD" | ||
218 | + else | ||
219 | + WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-universal-64" | ||
220 | + if [ -x $WRAPPER_TEST_CMD ] | ||
221 | + then | ||
222 | + WRAPPER_CMD="$WRAPPER_TEST_CMD" | ||
223 | + else | ||
224 | + if [ ! -x $WRAPPER_CMD ] | ||
225 | + then | ||
226 | + echo "Unable to locate any of the following binaries:" | ||
227 | + echo " $WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" | ||
228 | + echo " $WRAPPER_CMD-$DIST_OS-universal-32" | ||
229 | + echo " $WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64" | ||
230 | + echo " $WRAPPER_CMD-$DIST_OS-universal-64" | ||
231 | + echo " $WRAPPER_CMD" | ||
232 | + exit 1 | ||
233 | + fi | ||
234 | + fi | ||
235 | + fi | ||
236 | + fi | ||
237 | + else | ||
238 | + WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64" | ||
239 | + if [ -x $WRAPPER_TEST_CMD ] | ||
240 | + then | ||
241 | + WRAPPER_CMD="$WRAPPER_TEST_CMD" | ||
242 | + else | ||
243 | + if [ ! -x $WRAPPER_CMD ] | ||
244 | + then | ||
245 | + echo "Unable to locate any of the following binaries:" | ||
246 | + echo " $WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" | ||
247 | + echo " $WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64" | ||
248 | + echo " $WRAPPER_CMD" | ||
249 | + exit 1 | ||
250 | + fi | ||
251 | + fi | ||
252 | + fi | ||
253 | +fi | ||
254 | + | ||
255 | +# Build the nice clause | ||
256 | +if [ "X$PRIORITY" = "X" ] | ||
257 | +then | ||
258 | + CMDNICE="" | ||
259 | +else | ||
260 | + CMDNICE="nice -$PRIORITY" | ||
261 | +fi | ||
262 | + | ||
263 | +# Build the anchor file clause. | ||
264 | +if [ "X$IGNORE_SIGNALS" = "X" ] | ||
265 | +then | ||
266 | + ANCHORPROP= | ||
267 | + IGNOREPROP= | ||
268 | +else | ||
269 | + ANCHORPROP=wrapper.anchorfile=$ANCHORFILE | ||
270 | + IGNOREPROP=wrapper.ignore_signals=TRUE | ||
271 | +fi | ||
272 | + | ||
273 | +# Build the lock file clause. Only create a lock file if the lock directory exists on this platform. | ||
274 | +if [ -d $LOCKDIR ] | ||
275 | +then | ||
276 | + LOCKPROP=wrapper.lockfile=$LOCKFILE | ||
277 | +else | ||
278 | + LOCKPROP= | ||
279 | +fi | ||
280 | + | ||
281 | +checkUser() { | ||
282 | + # Check the configured user. If necessary rerun this script as the desired user. | ||
283 | + if [ "X$RUN_AS_USER" != "X" ] | ||
284 | + then | ||
285 | + # Resolve the location of the 'id' command | ||
286 | + IDEXE="/usr/xpg4/bin/id" | ||
287 | + if [ ! -x $IDEXE ] | ||
288 | + then | ||
289 | + IDEXE="/usr/bin/id" | ||
290 | + if [ ! -x $IDEXE ] | ||
291 | + then | ||
292 | + echo "Unable to locate 'id'." | ||
293 | + echo "Please report this message along with the location of the command on your system." | ||
294 | + exit 1 | ||
295 | + fi | ||
296 | + fi | ||
297 | + | ||
298 | + if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ] | ||
299 | + then | ||
300 | + # Already running as the configured user. Avoid password prompts by not calling su. | ||
301 | + RUN_AS_USER="" | ||
302 | + fi | ||
303 | + fi | ||
304 | + if [ "X$RUN_AS_USER" != "X" ] | ||
305 | + then | ||
306 | + # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be | ||
307 | + # able to create the lock file. The Wrapper will be able to update this file once it | ||
308 | + # is created but will not be able to delete it on shutdown. If $2 is defined then | ||
309 | + # the lock file should be created for the current command | ||
310 | + if [ "X$LOCKPROP" != "X" ] | ||
311 | + then | ||
312 | + if [ "X$2" != "X" ] | ||
313 | + then | ||
314 | + # Resolve the primary group | ||
315 | + RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1` | ||
316 | + if [ "X$RUN_AS_GROUP" = "X" ] | ||
317 | + then | ||
318 | + RUN_AS_GROUP=$RUN_AS_USER | ||
319 | + fi | ||
320 | + touch $LOCKFILE | ||
321 | + chown $RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE | ||
322 | + fi | ||
323 | + fi | ||
324 | + | ||
325 | + # Still want to change users, recurse. This means that the user will only be | ||
326 | + # prompted for a password once. | ||
327 | + su -m $RUN_AS_USER -s /bin/sh -c "$REALPATH $1" | ||
328 | + RETVAL=$? | ||
329 | + | ||
330 | + # Now that we are the original user again, we may need to clean up the lock file. | ||
331 | + if [ "X$LOCKPROP" != "X" ] | ||
332 | + then | ||
333 | + getpid | ||
334 | + if [ "X$pid" = "X" ] | ||
335 | + then | ||
336 | + # Wrapper is not running so make sure the lock file is deleted. | ||
337 | + if [ -f $LOCKFILE ] | ||
338 | + then | ||
339 | + rm $LOCKFILE | ||
340 | + fi | ||
341 | + fi | ||
342 | + fi | ||
343 | + | ||
344 | + exit $RETVAL | ||
345 | + fi | ||
346 | +} | ||
347 | + | ||
348 | +getpid() { | ||
349 | + if [ -f $PIDFILE ] | ||
350 | + then | ||
351 | + if [ -r $PIDFILE ] | ||
352 | + then | ||
353 | + pid=`cat $PIDFILE` | ||
354 | + if [ "X$pid" != "X" ] | ||
355 | + then | ||
356 | + # It is possible that 'a' process with the pid exists but that it is not the | ||
357 | + # correct process. This can happen in a number of cases, but the most | ||
358 | + # common is during system startup after an unclean shutdown. | ||
359 | + # The ps statement below looks for the specific wrapper command running as | ||
360 | + # the pid. If it is not found then the pid file is considered to be stale. | ||
361 | + if [ "$DIST_OS" = "solaris" ] | ||
362 | + then | ||
363 | + pidtest=`$PSEXE -p $pid -o comm | grep $WRAPPER_CMD | tail -1` | ||
364 | + else | ||
365 | + pidtest=`$PSEXE -p $pid -o command | grep $WRAPPER_CMD | tail -1` | ||
366 | + fi | ||
367 | + if [ "X$pidtest" = "X" ] | ||
368 | + then | ||
369 | + # This is a stale pid file. | ||
370 | + rm -f $PIDFILE | ||
371 | + echo "Removed stale pid file: $PIDFILE" | ||
372 | + pid="" | ||
373 | + fi | ||
374 | + fi | ||
375 | + else | ||
376 | + echo "Cannot read $PIDFILE." | ||
377 | + exit 1 | ||
378 | + fi | ||
379 | + fi | ||
380 | +} | ||
381 | + | ||
382 | +testpid() { | ||
383 | + pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` | ||
384 | + if [ "X$pid" = "X" ] | ||
385 | + then | ||
386 | + # Process is gone so remove the pid file. | ||
387 | + rm -f $PIDFILE | ||
388 | + pid="" | ||
389 | + fi | ||
390 | +} | ||
391 | + | ||
392 | +console() { | ||
393 | + echo "Running $APP_LONG_NAME..." | ||
394 | + getpid | ||
395 | + if [ "X$pid" = "X" ] | ||
396 | + then | ||
397 | + COMMAND_LINE="$CMDNICE $WRAPPER_CMD $WRAPPER_CONF wrapper.syslog.ident=$APP_NAME wrapper.pidfile=$PIDFILE $ANCHORPROP $LOCKPROP" | ||
398 | + exec $COMMAND_LINE | ||
399 | + else | ||
400 | + echo "$APP_LONG_NAME is already running." | ||
401 | + exit 1 | ||
402 | + fi | ||
403 | +} | ||
404 | + | ||
405 | +start() { | ||
406 | + echo "Starting $APP_LONG_NAME..." | ||
407 | + getpid | ||
408 | + if [ "X$pid" = "X" ] | ||
409 | + then | ||
410 | + if [ ! -d $DATADIR ]; then | ||
411 | + mkdir $DATADIR | ||
412 | + fi | ||
413 | + if [ ! -d $DATADIR/log ]; then | ||
414 | + mkdir $DATADIR/log | ||
415 | + fi | ||
416 | + COMMAND_LINE="$CMDNICE $WRAPPER_CMD $WRAPPER_CONF wrapper.syslog.ident=$APP_NAME wrapper.pidfile=$PIDFILE wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $LOCKPROP" | ||
417 | + exec $COMMAND_LINE | ||
418 | + else | ||
419 | + echo "$APP_LONG_NAME is already running." | ||
420 | + exit 1 | ||
421 | + fi | ||
422 | +} | ||
423 | + | ||
424 | +stopit() { | ||
425 | + echo "Stopping $APP_LONG_NAME..." | ||
426 | + getpid | ||
427 | + if [ "X$pid" = "X" ] | ||
428 | + then | ||
429 | + echo "$APP_LONG_NAME was not running." | ||
430 | + else | ||
431 | + if [ "X$IGNORE_SIGNALS" = "X" ] | ||
432 | + then | ||
433 | + # Running so try to stop it. | ||
434 | + kill $pid | ||
435 | + if [ $? -ne 0 ] | ||
436 | + then | ||
437 | + # An explanation for the failure should have been given | ||
438 | + echo "Unable to stop $APP_LONG_NAME." | ||
439 | + exit 1 | ||
440 | + fi | ||
441 | + else | ||
442 | + rm -f $ANCHORFILE | ||
443 | + if [ -f $ANCHORFILE ] | ||
444 | + then | ||
445 | + # An explanation for the failure should have been given | ||
446 | + echo "Unable to stop $APP_LONG_NAME." | ||
447 | + exit 1 | ||
448 | + fi | ||
449 | + fi | ||
450 | + | ||
451 | + # We can not predict how long it will take for the wrapper to | ||
452 | + # actually stop as it depends on settings in wrapper.conf. | ||
453 | + # Loop until it does. | ||
454 | + savepid=$pid | ||
455 | + CNT=0 | ||
456 | + TOTCNT=0 | ||
457 | + while [ "X$pid" != "X" ] | ||
458 | + do | ||
459 | + # Show a waiting message every 5 seconds. | ||
460 | + if [ "$CNT" -lt "5" ] | ||
461 | + then | ||
462 | + CNT=`expr $CNT + 1` | ||
463 | + else | ||
464 | + echo "Waiting for $APP_LONG_NAME to exit..." | ||
465 | + CNT=0 | ||
466 | + fi | ||
467 | + TOTCNT=`expr $TOTCNT + 1` | ||
468 | + | ||
469 | + sleep 1 | ||
470 | + | ||
471 | + testpid | ||
472 | + done | ||
473 | + | ||
474 | + pid=$savepid | ||
475 | + testpid | ||
476 | + if [ "X$pid" != "X" ] | ||
477 | + then | ||
478 | + echo "Failed to stop $APP_LONG_NAME." | ||
479 | + exit 1 | ||
480 | + else | ||
481 | + echo "Stopped $APP_LONG_NAME." | ||
482 | + fi | ||
483 | + fi | ||
484 | +} | ||
485 | + | ||
486 | +status() { | ||
487 | + getpid | ||
488 | + if [ "X$pid" = "X" ] | ||
489 | + then | ||
490 | + echo "$APP_LONG_NAME is not running." | ||
491 | + exit 1 | ||
492 | + else | ||
493 | + echo "$APP_LONG_NAME is running ($pid)." | ||
494 | + exit 0 | ||
495 | + fi | ||
496 | +} | ||
497 | + | ||
498 | +dump() { | ||
499 | + echo "Dumping $APP_LONG_NAME..." | ||
500 | + getpid | ||
501 | + if [ "X$pid" = "X" ] | ||
502 | + then | ||
503 | + echo "$APP_LONG_NAME was not running." | ||
504 | + | ||
505 | + else | ||
506 | + kill -3 $pid | ||
507 | + | ||
508 | + if [ $? -ne 0 ] | ||
509 | + then | ||
510 | + echo "Failed to dump $APP_LONG_NAME." | ||
511 | + exit 1 | ||
512 | + else | ||
513 | + echo "Dumped $APP_LONG_NAME." | ||
514 | + fi | ||
515 | + fi | ||
516 | +} | ||
517 | + | ||
518 | +case "$1" in | ||
519 | + | ||
520 | + 'console') | ||
521 | + checkUser $1 touchlock | ||
522 | + console | ||
523 | + ;; | ||
524 | + | ||
525 | + 'start') | ||
526 | + checkUser $1 touchlock | ||
527 | + start | ||
528 | + ;; | ||
529 | + | ||
530 | + 'stop') | ||
531 | + checkUser $1 | ||
532 | + stopit | ||
533 | + ;; | ||
534 | + | ||
535 | + 'restart') | ||
536 | + checkUser $1 touchlock | ||
537 | + stopit | ||
538 | + start | ||
539 | + ;; | ||
540 | + | ||
541 | + 'status') | ||
542 | + checkUser $1 | ||
543 | + status | ||
544 | + ;; | ||
545 | + | ||
546 | + 'dump') | ||
547 | + checkUser $1 | ||
548 | + dump | ||
549 | + ;; | ||
550 | + | ||
551 | + *) | ||
552 | + echo "Usage: $0 { console | start | stop | restart | status | dump }" | ||
553 | + exit 1 | ||
554 | + ;; | ||
555 | +esac | ||
556 | + | ||
557 | +exit 0 |
tools/package/wrapper/bin/onos-wrapper
0 → 100755
No preview for this file type
tools/package/wrapper/etc/onos-wrapper.conf
0 → 100644
1 | +# ------------------------------------------------------------------------ | ||
2 | +# Licensed to the Apache Software Foundation (ASF) under one or more | ||
3 | +# contributor license agreements. See the NOTICE file distributed with | ||
4 | +# this work for additional information regarding copyright ownership. | ||
5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
6 | +# (the "License"); you may not use this file except in compliance with | ||
7 | +# the License. You may obtain a copy of the License at | ||
8 | +# | ||
9 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | +# | ||
11 | +# Unless required by applicable law or agreed to in writing, software | ||
12 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | +# See the License for the specific language governing permissions and | ||
15 | +# limitations under the License. | ||
16 | +# ------------------------------------------------------------------------ | ||
17 | + | ||
18 | +#******************************************************************** | ||
19 | +# Wrapper Properties | ||
20 | +#******************************************************************** | ||
21 | +set.default.JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/ | ||
22 | +set.default.KARAF_HOME=/opt/onos/apache-karaf-3.0.1 | ||
23 | +set.default.KARAF_BASE=/opt/onos/apache-karaf-3.0.1 | ||
24 | +set.default.KARAF_DATA=/opt/onos/apache-karaf-3.0.1/data | ||
25 | +set.default.KARAF_ETC=/opt/onos/apache-karaf-3.0.1/etc | ||
26 | + | ||
27 | +# Java Application | ||
28 | +wrapper.working.dir=%KARAF_BASE% | ||
29 | +wrapper.java.command=%JAVA_HOME%/bin/java | ||
30 | +wrapper.java.mainclass=org.apache.karaf.wrapper.internal.Main | ||
31 | +wrapper.java.classpath.1=%KARAF_HOME%/lib/karaf-wrapper.jar | ||
32 | +wrapper.java.classpath.2=%KARAF_HOME%/lib/karaf.jar | ||
33 | +wrapper.java.classpath.3=%KARAF_HOME%/lib/karaf-jmx-boot.jar | ||
34 | +wrapper.java.classpath.4=%KARAF_HOME%/lib/karaf-jaas-boot.jar | ||
35 | +wrapper.java.classpath.5=%KARAF_HOME%/lib/karaf-wrapper-main.jar | ||
36 | +wrapper.java.classpath.6=%KARAF_HOME%/lib/karaf-org.osgi.core.jar | ||
37 | +wrapper.java.library.path.1=%KARAF_HOME%/lib/ | ||
38 | + | ||
39 | +# Application Parameters. Add parameters as needed starting from 1 | ||
40 | +#wrapper.app.parameter.1= | ||
41 | + | ||
42 | +# JVM Parameters | ||
43 | +# note that n is the parameter number starting from 1. | ||
44 | +wrapper.java.additional.1=-Dkaraf.home=%KARAF_HOME% | ||
45 | +wrapper.java.additional.2=-Dkaraf.base=%KARAF_BASE% | ||
46 | +wrapper.java.additional.3=-Dkaraf.data=%KARAF_DATA% | ||
47 | +wrapper.java.additional.4=-Dkaraf.etc=%KARAF_ETC% | ||
48 | +wrapper.java.additional.5=-Dcom.sun.management.jmxremote | ||
49 | +wrapper.java.additional.6=-Djavax.management.builder.initial=org.apache.karaf.management.boot.KarafMBeanServerBuilder | ||
50 | +wrapper.java.additional.7=-Dkaraf.startLocalConsole=false | ||
51 | +wrapper.java.additional.8=-Dkaraf.startRemoteShell=true | ||
52 | +wrapper.java.additional.9=-Djava.endorsed.dirs=%JAVA_HOME%/jre/lib/endorsed:%JAVA_HOME%/lib/endorsed:%KARAF_HOME%/lib/endorsed | ||
53 | +wrapper.java.additional.10=-Djava.ext.dirs=%JAVA_HOME%/jre/lib/ext:%JAVA_HOME%/lib/ext:%KARAF_HOME%/lib/ext | ||
54 | + | ||
55 | +# Uncomment to enable jmx | ||
56 | +#wrapper.java.additional.n=-Dcom.sun.management.jmxremote.port=1616 | ||
57 | +#wrapper.java.additional.n=-Dcom.sun.management.jmxremote.authenticate=false | ||
58 | +#wrapper.java.additional.n=-Dcom.sun.management.jmxremote.ssl=false | ||
59 | + | ||
60 | +# Uncomment to enable YourKit profiling | ||
61 | +#wrapper.java.additional.n=-Xrunyjpagent | ||
62 | + | ||
63 | +# Uncomment to enable remote debugging | ||
64 | +#wrapper.java.additional.n=-Xdebug -Xnoagent -Djava.compiler=NONE | ||
65 | +#wrapper.java.additional.n=-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 | ||
66 | + | ||
67 | +# Initial Java Heap Size (in MB) | ||
68 | +#wrapper.java.initmemory=3 | ||
69 | + | ||
70 | +# Maximum Java Heap Size (in MB) | ||
71 | +wrapper.java.maxmemory=512 | ||
72 | + | ||
73 | + | ||
74 | +#******************************************************************** | ||
75 | +# Wrapper Logging Properties | ||
76 | +#******************************************************************** | ||
77 | +# Format of output for the console. (See docs for formats) | ||
78 | +wrapper.console.format=PM | ||
79 | + | ||
80 | +# Log Level for console output. (See docs for log levels) | ||
81 | +wrapper.console.loglevel=INFO | ||
82 | + | ||
83 | +# Log file to use for wrapper output logging. | ||
84 | +wrapper.logfile=%KARAF_DATA%/log/wrapper.log | ||
85 | + | ||
86 | +# Format of output for the log file. (See docs for formats) | ||
87 | +wrapper.logfile.format=LPTM | ||
88 | + | ||
89 | +# Log Level for log file output. (See docs for log levels) | ||
90 | +wrapper.logfile.loglevel=INFO | ||
91 | + | ||
92 | +# Maximum size that the log file will be allowed to grow to before | ||
93 | +# the log is rolled. Size is specified in bytes. The default value | ||
94 | +# of 0, disables log rolling. May abbreviate with the 'k' (kb) or | ||
95 | +# 'm' (mb) suffix. For example: 10m = 10 megabytes. | ||
96 | +wrapper.logfile.maxsize=10m | ||
97 | + | ||
98 | +# Maximum number of rolled log files which will be allowed before old | ||
99 | +# files are deleted. The default value of 0 implies no limit. | ||
100 | +wrapper.logfile.maxfiles=5 | ||
101 | + | ||
102 | +# Log Level for sys/event log output. (See docs for log levels) | ||
103 | +wrapper.syslog.loglevel=NONE | ||
104 | + | ||
105 | +#******************************************************************** | ||
106 | +# Wrapper Windows Properties | ||
107 | +#******************************************************************** | ||
108 | +# Title to use when running as a console | ||
109 | +wrapper.console.title=onos | ||
110 | + | ||
111 | +#******************************************************************** | ||
112 | +# Wrapper Windows NT/2000/XP Service Properties | ||
113 | +#******************************************************************** | ||
114 | +# WARNING - Do not modify any of these properties when an application | ||
115 | +# using this configuration file has been installed as a service. | ||
116 | +# Please uninstall the service before modifying this section. The | ||
117 | +# service can then be reinstalled. | ||
118 | + | ||
119 | +# Name of the service | ||
120 | +wrapper.ntservice.name=onos | ||
121 | + | ||
122 | +# Display name of the service | ||
123 | +wrapper.ntservice.displayname=onos | ||
124 | + | ||
125 | +# Description of the service | ||
126 | +wrapper.ntservice.description=ONOS | ||
127 | + | ||
128 | +# Service dependencies. Add dependencies as needed starting from 1 | ||
129 | +wrapper.ntservice.dependency.1= | ||
130 | + | ||
131 | +# Mode in which the service is installed. AUTO_START or DEMAND_START | ||
132 | +wrapper.ntservice.starttype=AUTO_START | ||
133 | + | ||
134 | +# Allow the service to interact with the desktop. | ||
135 | +wrapper.ntservice.interactive=false |
tools/package/wrapper/lib/karaf-wrapper.jar
0 → 100644
No preview for this file type
tools/package/wrapper/lib/libwrapper.so
0 → 100644
No preview for this file type
tools/test/README
0 → 100644
1 | +Artifacts for system testing onos. |
tools/test/bin/onos-install
0 → 100755
1 | +#!/bin/bash | ||
2 | +#------------------------------------------------------------------------------- | ||
3 | +# Remotely pushes bits to a remote machine and install & starts ONOS. | ||
4 | +#------------------------------------------------------------------------------- | ||
5 | + | ||
6 | +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 | ||
7 | +. $ONOS_ROOT/tools/build/envDefaults | ||
8 | + | ||
9 | +# If the first option is -f attempt uninstall first. | ||
10 | +[ "$1" = "-f" ] && shift && onos-uninstall ${1:-$OCI} | ||
11 | + | ||
12 | +remote=$ONOS_USER@${1:-$OCI} | ||
13 | + | ||
14 | +scp -q $ONOS_TAR $remote:/tmp | ||
15 | + | ||
16 | +ssh $remote " | ||
17 | + [ -d $ONOS_INSTALL_DIR/bin ] && echo \"ONOS is already installed\" && exit 1 | ||
18 | + | ||
19 | + sudo mkdir -p $ONOS_INSTALL_DIR && sudo chown sdn:sdn $ONOS_INSTALL_DIR | ||
20 | + tar zxmf /tmp/$ONOS_BITS.tar.gz -C $ONOS_INSTALL_DIR --strip-components=1 | ||
21 | + | ||
22 | + ln -s /opt/onos/$KARAF_DIST/data/log /opt/onos/log | ||
23 | + | ||
24 | +" |
tools/test/bin/onos-uninstall
0 → 100755
1 | +#!/bin/bash | ||
2 | +#------------------------------------------------------------------------------- | ||
3 | +# Remotely stops & uninstalls ONOS. | ||
4 | +#------------------------------------------------------------------------------- | ||
5 | + | ||
6 | +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 | ||
7 | +. $ONOS_ROOT/tools/build/envDefaults | ||
8 | + | ||
9 | +remote=$ONOS_USER@${1:-$OCI} | ||
10 | + | ||
11 | +ssh $remote " | ||
12 | + [ -f $ONOS_INSTALL_DIR/bin/onos ] && \ | ||
13 | + $ONOS_INSTALL_DIR/bin/onos halt 2>/dev/null | ||
14 | + sudo rm -fr $ONOS_INSTALL_DIR | ||
15 | +" |
... | @@ -230,6 +230,10 @@ public final class IpAddress { | ... | @@ -230,6 +230,10 @@ public final class IpAddress { |
230 | return new IpAddress(version, host, netmask); | 230 | return new IpAddress(version, host, netmask); |
231 | } | 231 | } |
232 | 232 | ||
233 | + public boolean isMasked() { | ||
234 | + return mask() != 0; | ||
235 | + } | ||
236 | + | ||
233 | @Override | 237 | @Override |
234 | public int hashCode() { | 238 | public int hashCode() { |
235 | final int prime = 31; | 239 | final int prime = 31; | ... | ... |
-
Please register or login to post a comment